Brian Keith
Brian Keith

Reputation: 328

Git push branch from different checked out branch

Can you 'git push origin branch1' while you have branch2 checked out?

git checkout branch1
git commit -am 'changes 1'
git checkout branch2
git commit -am 'changes 2'
git push origin branch1

Will that only push branch1 to the remote repo or will branch2 changes be pushed?

Upvotes: 3

Views: 557

Answers (2)

cforbish
cforbish

Reputation: 8819

It depends on what push.default is configured to. If you git config push.default = matching and you have remote branches branch1 and branch2, yes both branch1 and branch2 will be push.

Final answer is to use -n to see what would happen without actually pushing:

git push -n

Upvotes: 0

Peter Lundgren
Peter Lundgren

Reputation: 9197

git push <repository> <refspec>

Will only push the specified refs to the remote specified. In the case where <refspec> is a branch name, only that remote branch will be updated.

If <refspec> is not specified, the behavior is controlled by the push.default configuration variable.

More information is available on the git-push(1) and git-config(1) man pages.

Upvotes: 1

Related Questions