git push origin master和git push之间的区别

Res*_*had 10 git

这两个命令之间有什么区别.

git push origin mastergit push

当我使用第一个(git push origin master)它以某种方式将它2x发送到上游并且只git push发送它1x.

这里有谁能解释为什么会这样?

Tho*_*ger 8

通过指定$ git push没有存储库参数,默认情况下它会将当前分支推送到跟踪远程分支.

指定时,$ git push origin您明确地将更改推送到origin远程存储库.

至于你向上游发送"2x"的问题,这不应该是行为.它会将更改一次性推送到上游存储库.

关于git-push的文档

当你做一个$ git push没有参数的时候,Git实际上对它所采取的行动非常冗长:

warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Run Code Online (Sandbox Code Playgroud)