James Raitsev
James Raitsev

Reputation: 96581

Git, pushing to remote

Lets suppose i am in a local ABC with branches branch_A and branch_B.

From repo_A, what are the differences between:

 - git push origin
 - git push origin branch_A
 - git push origin branch_A:branch_A

The reason for question is the following sequence of events, i find to be surprising:

11:05:56 ~/blah $ git push origin
Counting objects: 31, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (17/17), 1.28 KiB, done.
Total 17 (delta 10), reused 0 (delta 0)
To ssh://git@mygit/myrepo.git
   141fc0d..d42c3b6  branch_B -> branch_B    // While i was in branch_A

11:06:02 ~/blah $ git branch
  branch_A
* branch_B 

Upvotes: 2

Views: 113

Answers (1)

Mark Longair
Mark Longair

Reputation: 468191

The default behaviour of behaviour of git push origin (if you haven't customized the config option push.default) is to push all "matching" branches. That means that each local branch is pushed to one with the same name in origin so long as a branch with that name already exists in origin. In this case, it seems that you have a branch_B branch in origin as well as locally.

The two other variants you quoted:

git push origin branch_A
git push origin branch_A:branch_A

.... are actually equivalent - if you don't include the : in the refspec to separate the source name from the destination name, it assumes that you mean the same name in the source and destination.

Upvotes: 1

Related Questions