Reputation: 10300
I want to have two branches locally (e.g. a-local
and b-local
) and two branches remotely (e.g. a-remote
, b-remote
), and they match in pairs (e.g. a-local
- a-remote
, etc). How do I make sure I don't accidentally push a local branch to a wrong remote branch (e.g. a-local
-> b-remote
)?
I'm using git 1.8.2.3.
Upvotes: 1
Views: 781
Reputation: 8809
Before actually pushing do add a -n
to the command. This shows which local branch(s) will be pushed to which remote and remote branch(s) without actually doing the push. Then you can revise the command, still using -n
and finally when happy, remove the -n
.
One thing that I have done is configure the global option of push.default to upstream by git config --global push.default upstream
. The default value is matching, which will attempt to push each matching branch.
If your remote is known as origin
(probably is) the command to push changes on a-local would be git push origin a-local:a-remote -n
. But a simple git push -n
might function based on push.default and upstream configuration (see kirelagin's note).
Upvotes: 1
Reputation: 13606
Wow, it's hard to do this accidentally.
Once you do git push --set-upstream origin a-local:a-remote
to make it tracking (and the same for the other pair), you can push with just git checkout a-local; git push
or git-push a-local
and I should say you'll have to try hard to accidentally push to a wrong branch…
Upvotes: 0