我使用以下命令推送到我的远程分支:
git push origin sandbox
如果我说
git push origin
这是否也会将更改推送到我的其他分支,还是只更新我当前的分支?我有三个分支:master
、production
和 sandbox
。
git push
文档对此不是很清楚,所以我想澄清一下。
以下 git push
命令准确地更新了哪些分支和远程?
git push
git push origin
上面的 origin
是一个 Remote 。
我知道 git push [remote] [branch]
只会将那个分支推送到远程。
最佳答案
您可以通过在 git 配置中设置 push.default 来控制默认行为。来自 the git-config(1) documentation :
push.default
定义 git push 在命令行上没有给出 refspec 时应该采取的操作,远程中没有配置 refspec,并且命令行上给出的任何选项都没有暗示 refspec。可能的值是:
nothing
:不推送任何内容匹配
:(Git 2.0之前默认)推送所有匹配的分支两端同名的所有分支都被认为是匹配的。
upstream
:将当前分支推送到它的upstream分支(tracking
是upstream的弃用同义词)current
:将当前分支推送到同名分支简单
:(Git 1.7.11 新增,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
命令行示例:
查看当前配置:
git config push.default
设置新配置:
git config push.default current
关于git - 没有指定分支的 "git push"的默认行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/948354/