“git push”的默认行为没有指定分支 [英] Default behavior of "git push" without a branch specified
问题描述
我使用以下命令推送到我的远程分支:
git push origin沙箱
如果我说
git推送起源
是否也会在其他分支中推送更改,还是只更新当前分支?我有三个分支: master
, production
和 sandbox
。
git push 文档对此不太清楚,所以我想澄清一下。
下面的 git push
命令更新了哪些分支和远程?
git push
git push origin
我知道 git push [remote您可以控制默认设置。[/ div>] [branch]
只会将该分支推送到远程。
push.default
定义动作如果没有在命令行上给出refspec,那么在远程中没有配置refspec,并且在命令行上给出的任何选项都没有暗示refspec。可能的值有:
nothing
:不要推送任何内容
$匹配:推送所有匹配的分支
所有在两端具有相同名称的分支都被认为是匹配的。
这是Git 1.x中的默认值。
这是最安全的选择,非常适合初学者。 将成为默认的Git 2.0。 命令行示例: 查看当前配置: upstream
:将当前分支推送到其上游分支( tracking >是不推荐的同义词对于上游)
current
:将当前分支推送到同名分支
简单
:(Git 1.7.11中的新增内容)like upstream,但拒绝推送上游分支的名称与本地不同
$ g $ git config --global push.default
设置新配置:
git config --global push.default current
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
.
The git push
documentation is not very clear about this, so I'd like to clarify this for good.
Which branches and remotes do the following git push
commands update exactly?
git push
git push origin
origin
above is a remote.
I understand that git push [remote] [branch]
will push only that branch to the remote.
You can control the default behavior by setting push.default in your git config. From the git-config(1) documentation:
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. Possible values are:
nothing
: do not push anythingmatching
: push all matching branchesAll branches having the same name in both ends are considered to be matching.
This is the default in Git 1.x.
upstream
: push the current branch to its upstream branch (tracking
is a deprecated synonym for upstream)current
: push the current branch to a branch of the same namesimple
: (new in Git 1.7.11) like upstream, but refuses to push if the upstream branch's name is different from the local oneThis is the safest option and is well-suited for beginners.
This will become the default in 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
这篇关于“git push”的默认行为没有指定分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!