git push origin 和 git push origin master 有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12462481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:36:36  来源:igfitidea点击:

What is the difference between git push origin and git push origin master

gitgit-pushgit-remote

提问by Hilbert-

Is there any difference in pushing the master branch of a local git repository to the master branch of a remote repository called origin with git push origin masteror with git push origin?

将本地 git 存储库的 master 分支推送到名为 origin withgit push origin master或 with的远程存储库的 master 分支有什么区别git push origin吗?

采纳答案by ouah

The default action of git pushand git push originhas changed since gitversion 1.7.11:

的默认操作git pushgit push origin自改变git版本1.7.11

  • Before 1.7.11, git pushby default pushes all branches that also exist remotely with the same name.

  • Since 1.7.11, git pushby default pushes the current branch to a remote branch with the same name.

  • 之前1.7.11git push默认情况下推送所有远程存在的同名分支。

  • 由于1.7.11git push默认情况下将当前分支推送到具有相同名称的远程分支。

Before and after version 1.7.11, the default behavior can be configured with the push.defaultconfiguration option. This configuration option has been introduced in gitversion 1.6.3.

在 version 之前和之后1.7.11,可以使用push.default配置选项配置默认行为。此配置选项已在git版本中引入1.6.3

回答by bluesman

git push origin master

This only pushes your master branch to origin

这只会将您的主分支推送到原点

git push origin

Pushes all your branches to origin

将所有分支推送到原点

UPDATE - The behavior of Git has changed since this answer was written. git push originon Git >=2.0 by default pushes the current branch to a matching branch of the same name, but this behavior can be overridden via git config

更新 - 自编写此答案以来,Git 的行为已发生变化。 git push origin在 Git >=2.0 默认情况下,将当前分支推送到相同名称的匹配分支,但可以通过覆盖此行为git config