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.
精彩评论