开发者

How do I make a local branch track a remote branch with a different name?

I have a setup with two servers (staging and production). Both of these h开发者_如何学Pythonas a master branch I can push to (I use heroku, not that it matters though).

Currently, I can push to staging with this command:

git push staging master

Which will push my local master branch. However, I would like to have a local branch named staging, which will push to the remote repository staging/master. How can this be done?


To always push to tracking:

First, make sure the config option push.default is set to tracking:

git config push.default tracking

Second, set the upstream for your local branch:

git branch --set-upstream <localbranch> <remotename>/<remotebranch>

To only push one particular branch to a particular different remote branch

Alternatively, if you wanted to keep the default push behavior (push all branches to matching on remote), you could just individually tell Git that when pushing to that particular remote, your local branch actually "matches" a different one on the remote:

git config remote.<remotename>.push refs/heads/<localbranch>:refs/heads/<remotebranch>

For more details on Git configuration options, see here:

http://git-scm.com/docs/git-config


To do it manually,

git push staging staging:master

I'd suggest maybe setting up a configuration that would allow you to do it automatically, though:

git config remote.staging.push refs/heads/staging:refs/heads/master

which tells git to push the local staging branch to master on the remote side (i.e. the staging remote) (if I remember the syntax correctly), and optionally

git config branch.staging.remote staging

which will tell git that if you have staging checked out and just type git push, it should push to the staging remote.

Of course I think you can do this using git branch and git remote, but I just went through the process of creating a similar setup (2 servers) and I found it easier to just work with the configurations directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜