Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

git - 没有指定分支的“git push”的默认行为(Default behavior of “git push” without a branch specified)

I use the following command to push to my remote branch:

(我使用以下命令推送到我的远程分支:)

git push origin sandbox

If I say

(如果我说)

git push origin

does that push changes in my other branches too, or does it only update my current branch?

(这会推动我的其他分支的变化,还是只更新我当前的分支?)

I have three branches: master , production and sandbox .

(我有三个分支: masterproductionsandbox 。)

The git push documentation is not very clear about this, so I'd like to clarify this for good.

(git push文档对此并不十分清楚,所以我想澄清这一点。)

Which branches and remotes do the following git push commands update exactly?

(哪些分支和遥控器执行以下git push命令更新?)

git push 
git push origin

origin above is a remote.

(上面的origin是遥远的。)

I understand that git push [remote] [branch] will push only that branch to the remote.

(据我所知, git push [remote] [branch]只会将该分支推送到远程。)

  ask by PlagueHammer translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can control the default behavior by setting push.default in your git config.

(您可以通过在git config中设置push.default来控制默认行为。)

From the git-config(1) documentation :

(从git-config(1)文档 :)

push.default

Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line.

(如果在命令行上没有给出refspec,在远程中没有配置refspec,并且命令行上给出的任何选项都没有暗示refspec,则定义git push应采取的操作。)

Possible values are:

(可能的值是:)

  • nothing : do not push anything

    (nothing :不要推动任何东西)

  • matching : push all matching branches

    (matching :推送所有匹配的分支)

    All branches having the same name in both ends are considered to be matching.

    (两端具有相同名称的所有分支都被认为是匹配的。)

    This used to be the default, but not since Git 2.0 ( simple is the new default).

    (这曾经是默认值,但不是因为Git 2.0( simple是新的默认值)。)

  • upstream : push the current branch to its upstream branch ( tracking is a deprecated synonym for upstream)

    (upstream :将当前分支推送到其上游分支( tracking是上游的弃用同义词))

  • current : push the current branch to a branch of the same name

    (current :将当前分支推送到同名分支)

  • simple : (new in Git 1.7.11) like upstream, but refuses to push if the upstream branch's name is different from the local one

    (simple :(在Git 1.7.11中新增)像上游一样,但如果上游分支的名称与本地名称不同,则拒绝推送)

    This is the safest option and is well-suited for beginners.

    (这是最安全的选择,非常适合初学者。)

    This mode has become the default in Git 2.0.

    (此模式已成为Git 2.0中的默认模式。)

The simple, current and upstream modes are for those who want to push out a single branch after finishing work, even when the other branches are not yet ready to be pushed out

(简单,当前和上游模式适用于那些想要在完成工作后推出单个分支的人,即使其他分支尚未准备好被推出)

Command line examples:

(命令行示例:)

To view the current configuration:

(要查看当前配置:)

git config --global push.default

To set a new configuration:

(要设置新配置:)

git config --global push.default current

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...