8

I worked on my local feature branch, foo. Then I wanted to push that new branch to origin so others could work on it. The normal way to do this is:

git push origin foo:foo

Which I eventually did, and it worked completely as expected, pushing up 61 objects. Before doing that, on a whim, I tried:

git push origin

Thinking maybe it would default to making a new remote branch based on the name of my local branch. The output was normal push output, with only 13 objects pushed up. The results were imperceivable. Nothing new showed up for the other devs or in my local repo after a fetch.

So what does git think I'm telling it to do when I do git push origin, and what effect, if any, did it have on my remote repo?

John Bachir
  • 22,495
  • 29
  • 154
  • 227
  • 3
    `git help push` should give you all the information you want to know. There's a section on what `git push origin` does and what configuration options affect what it does. http://www.kernel.org/pub/software/scm/git/docs/git-push.html – CB Bailey Jan 03 '11 at 17:29

2 Answers2

12

It depends on your git version. In old version, it would try to push each and every local branche that is also present on the distant side. Since version 1.6.3, the behaviour is controlled by the push.default configuration option.

Values are:

  • matching : [the default] push all branch with same local and distant name
  • nothing : push nothing
  • tracking : will only push the current branch if it is tracking a distant branch
  • current : will push current branch
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85
4

June 2012: [ANNOUNCE] Git 1.7.11.rc1

A new mode for push, "simple", which is a cross between "current" and "upstream", has been introduced.
"git push" without any refspec will push the current branch out to the same name at the remote repository only when it is set to track the branch with the same name over there.
The plan is to make this mode the new default value when push.default is not configured.


March 2012: Beware: that default "matching" policy might change soon
(sometime after Git1.7.10+)
:

See "Please discuss: what "git push" should do when you do not say what to push?"

In the current setting (i.e. push.default=matching), git push without argument will push all branches that exist locally and remotely with the same name.
This is usually appropriate when a developer pushes to his own public repository, but may be confusing if not dangerous when using a shared repository.

The proposal is to change the default to 'upstream', i.e. push only the current branch, and push it to the branch git pull would pull from.
Another candidate is 'current'; this pushes only the current branch to the remote branch of the same name.

What has been discussed so far can be seen in this thread:

http://thread.gmane.org/gmane.comp.version-control.git/192547/focus=192694

Previous relevant discussions include:

To join the discussion, send your messages to: git@vger.kernel.org

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250