开发者

What is the result of `git push origin`?

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开发者_C百科.

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?


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


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:

  • http://thread.gmane.org/gmane.comp.version-control.git/123350/focus=123541
  • http://thread.gmane.org/gmane.comp.version-control.git/166743

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜