Git 使用 Heroku 将当前分支推送到远程
我正在尝试在 Heroku 上创建一个暂存分支,但有些东西我不太明白。
假设我已经创建了一个heroku应用程序并将遥控器设置为指向staging-remote,如果我这样做:
git checkout -b staging staging-remote/master
我会得到一个名为“staging”的本地分支,它跟踪staging-remote/master - 或者这就是我的想法......
但是:
git remote show staging-remote
给了我这个:
remote staging
Fetch URL: [email protected]:myappname.git
Push URL: [email protected]:myappname.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
staging-remote merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
正如你所看到的,拉动看起来合理,但默认的推力却不然。这意味着如果我这样做:
git push staging-remote
我会将本地 master 分支推送到 staging 分支。但这不是我想要的......基本上,我想将更新合并到我的暂存分支中,然后轻松地将其推送到heroku,而不必像这样指定分支:
git push staging-remote mybranch:master
上面的操作并不难,但我想避免意外地执行先前的推送并推送错误的分支...这对于我想要创建的生产分支来说非常重要!
我试过搞乱 git config,但还没想出如何解决这个问题......
I'm trying to create a staging branch on Heroku, but there's something I don't quite get.
Assuming I've already created a heroku app and setup the remote to point to staging-remote, If I do:
git checkout -b staging staging-remote/master
I get a local branch called 'staging' which tracks staging-remote/master - or that's what I thought....
But:
git remote show staging-remote
Gives me this:
remote staging
Fetch URL: [email protected]:myappname.git
Push URL: [email protected]:myappname.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
staging-remote merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
As you can see, the pull looks reasonable, but the default push does not. It implies that if I do:
git push staging-remote
I'm going to push my local master branch up to the staging branch. But that's not what I want.... Basically, I want to merge updates into my staging branch, then easily push it to heroku without having to specify the branch like so:
git push staging-remote mybranch:master
The above isn't hard to do, but I want to avoid accidentally doing the previous push and pushing the wrong branch... This is doubly important for the production branch I'd like to create!
I've tried messing with git config, but haven't figured out how to get this right yet...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我已经测试过了,@juba 和 @MatthewFord 的版本运行完美!
这会将名为 staging 的本地主题分支推送到名为 staging 的远程存储库上的远程分支 master 中。
@nickgrim 将它的通用形式如下:
更新:
此外,当您使用
-
git Push
时,现代 git 将方便地为您运行上述配置命令u 选项:I have tested it and @juba and @MatthewFord's versions work perfectly!
This pushes my local topic branch named staging into remote branch master on the remote repository named staging.
@nickgrim put it in the general form like so:
Update:
Furthermore, modern git will conveniently run the above configuration command for you when you
git push
with the-u
option:我有一个名为heroku的分支,这对我有用:
您面临的问题是heroku忽略除master之外的所有分支。
I have a branch called heroku, and this worked for me:
the problem you're facing is heroku ignores all branches other than master.
摘自《O'Reilly - 使用 Git 进行版本控制》一书第 184 页 |第 11 章:远程存储库
这就是为什么朱巴的例子应该失败的原因。更正后的 refspec 应该是:
From the book "O’Reilly - Version Control with Git" page 184 | Chapter 11: Remote Repositories
That’s why the example from juba should fail. the corrected refspec should be:
从 Everiday Git with 20 个命令左右 页面:
http://www.kernel.org/pub/software/scm/git/docs/everyday.html
看来你可以通过在本地添加一个配置指令来实现你想要做的事情git 存储库,类似于:
然后,如果您从 mybranch 本地分支执行
git Push
,它应该被推送到 master 分支您的staging-remote遥控器。尽管如此,请使用 git remote show staging-remote 进行验证,并在使用之前仔细测试它,因为我距离 git 专家还很远......
From the page Everiday Git with 20 commands or so :
http://www.kernel.org/pub/software/scm/git/docs/everyday.html
It seems that you can achieve what you want to do by adding a config directive to your local git repository, something like :
Then, if you do a
git push
from your mybranch local branch, it should be pushed to the master branch of your staging-remote remote.Nevertheless, please verify with
git remote show staging-remote
and carefully test it before using it, as I'm far from a git expert...我无法找到一种方法来做到这一点,但最终我找到了一个方便的 rake 任务来使它变得简单:
http://www.jbarnette.com/2009/11/ 10/部署到heroku.html
I couldn't figure out a way to do this, but in the end I found a handy rake task to make it easy:
http://www.jbarnette.com/2009/11/10/deploying-to-heroku.html
我遇到了同样的问题,试图弄清楚如何处理 Heroku 忽略除“master”之外的所有分支的政策。如果你只能在 Heroku 上测试主分支,那么它有点违背了保留单独分支的全部意义。
这种限制的结果是,无论我正在处理哪个本地主题分支,我都希望有一种简单的方法将 Heroku 的 master 切换到该本地主题分支,并执行“git push -f”来覆盖 Heroku 上的 master 。不用说,拥有一个单独的远程存储库(如 Github)是一个非常好的主意,可以在不受此限制的情况下备份所有内容。我将其称为“origin”,并使用 Heroku 的“heroku”,以便“git Push”始终备份所有内容。
我从阅读 http://progit.org/book/ 的“Pushing Refspecs”部分得到了什么ch9-5.html 是
git push heroku local-topic-branch:refs/heads/master
我真正想要的是一种在配置文件中设置它的方法,以便“git push heroku”始终执行上面,将“local-topic-branch”替换为我当前分支的名称。
我可能会问这个新问题,看看其他人是否已经弄清楚如何做到这一点。
I'm having the same problem trying to figure out how to deal with Heroku's policy of ignoring all branches but 'master'. It kinda defeats the whole point of keeping separate branches if you can only ever test the master branch on Heroku.
The consequence of this restriction is that whatever local topic branch I may be working on, I'd like an easy way to switch Heroku's master to that local topic branch and do a "git push -f" to over-write master on Heroku. Needless to say, it would be a very good idea to have a separate remote repository (like Github), to back everything up without this restriction. I'd call that one "origin" and use "heroku" for Heroku so that "git push" always backs up everything.
What I got from reading the "Pushing Refspecs" section of http://progit.org/book/ch9-5.html is
git push heroku local-topic-branch:refs/heads/master
What I'd really like is a way to set this up in the config file so that "git push heroku" always does the above, replacing "local-topic-branch" with the name of whatever my current branch happens to be.
I may ask this as a new question, to see if anyone else has figured out how to do this.
这有效。我已经多次使用它来设置带有 git-flow、heroku 和备份 git 服务的客户端。
存储库的 .git/config:
一切正常:
git Push origin
git pull origin
git Push staging
git Push Production
将 fetch 和 push 想象成 stdout 和 stdin,两者都可以以一种方式重定向或关闭。另外,如果有人知道如何在不破解 .git/config 的情况下获取这些设置,请随时进行编辑修改,业力点肯定会随之而来。
This works. I have used it more than a few times for setting up clients with git-flow, heroku, and a backup git service.
.git/config for the repo:
All working correctly:
git push origin
git pull origin
git push staging
git push production
Think about fetch and push as like stdout and stdin, where both can be redirected or closed to be one way. Also if anyone knows how to get these settings without hacking .git/config, please feel free to amend with an edit, karma points are sure to follow.