`git config` 和 `git push --set-upstream` 有什么区别
问题
:
$ git remote add origin [email protected]:yourname/yourproject.git
$ git config remote.origin.push refs/heads/master:refs/heads/master
$ git push
和:
$ git remote add origin [email protected]:yourname/yourproject.git
$ git push origin master -u
第二个版本只是比第一个版本更新且短,还是有其他差异?
背景研究
从 Git 1.7.0 开始,您可以将 --set-upstream
选项与 git push
一起使用。根据 git push 手册:
-u, --set-upstream 对于每个最新或成功推送的分支,添加上游 (跟踪)参考,由无参数 git-pull(1) 和其他命令使用。为了 更多信息,请参阅 git-config(1) 中的branch.
.merge。
Question
What's the difference between:
$ git remote add origin [email protected]:yourname/yourproject.git
$ git config remote.origin.push refs/heads/master:refs/heads/master
$ git push
and:
$ git remote add origin [email protected]:yourname/yourproject.git
$ git push origin master -u
Is the second version simply newer and shorter than the first version, or are there other differences?
Background Research
As of Git 1.7.0, you can use the --set-upstream
option with git push
. According to the git push
manual:
-u, --set-upstream For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch.<name>.merge in git-config(1).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这些是非常不同的。第一个配置设置
remote..push
在未指定其他引用规范的情况下设置用于推送的默认引用规范。默认情况下,执行 git push origin 会将每个分支推送到具有匹配名称的分支,只要远程上已存在具有该名称的分支即可。完成后:...你会发现
git push origin
只会将master
推送到master
。如果推送成功,您引用的另一个命令 git push -u origin master 会设置两个不同的配置选项:
branch.master.remote
设置为origin
branch.master.merge
设置为refs/heads/master
这些本质上是说
master
在origin 应该被视为您的默认“上游”分支
到master
分支。它们最明显的效果是当您在master
上时为git pull
提供默认操作,但也可用于各种其他情况,例如提供有用的消息在git status
的顶部,告诉您master
与origin/master
的比较情况。但是,这些设置不用于通知git Push
和git Push origin
的默认操作,除非您还设置了配置选项< code>push.defaulttracking
(或最近版本中的upstream
)。因此,作为一个非常近似的总结,设置
remote..push
会影响git push
的默认操作,而git push -u origin master< /code> 设置通常只影响 git pull 操作的配置选项。
No, these are very different. The first config setting,
remote.<name>.push
sets a default refspec for pushing if no other refspec is specified. By default, doinggit push origin
will push every branch to a branch with a matching name so long as a branch with that name already existed on the remote. After doing:... you will find that
git push origin
will just pushmaster
tomaster
.The other command you quote,
git push -u origin master
, sets two different config options if the push is successful:branch.master.remote
is set toorigin
branch.master.merge
is set torefs/heads/master
These essentially say that
master
inorigin
should be regarded as the default "upstream" branch of yourmaster
branch. Their most obvious effect is to provide a default action forgit pull
when you are onmaster
, but are also used in a variety of other situations, such as providing the helpful message at the top ofgit status
that tells you wheremaster
is compared toorigin/master
. These settings are not, however, used to inform the default action ofgit push
andgit push origin
unless you have also set the config optionpush.default
totracking
(orupstream
in recent versions).So, as a very approximate summary, setting
remote.<name>.push
affects the default action ofgit push
, whilegit push -u origin master
sets config options that usually just affect the action ofgit pull
.