`git config`和`git push --set-upstream`有什么区别 [英] What's the difference between `git config` and `git push --set-upstream`
问题描述
问题
有什么区别:
$ git remote add origin git@github.com:yourname / yourproject.git
$ git config remote.origin.push refs / heads / master:refs / heads / master
$ git push
code>
和:
$ git remote add origin git@github.com: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)中的分支。< name> .merge。
是非常不同的。如果没有指定其他refspec,第一个配置设置 remote。< name> .push
会为推送设置默认的refspec。默认情况下,只要具有该名称的分支已经在远程存在,那么执行 git push origin
会将每个分支推送到具有匹配名称的分支。做完之后:
git config remote.origin.push refs / heads / master:refs / heads / master
...你会发现 git push origin
master
至 master
。
, git push -u origin master
,如果推送成功,设置两个不同的配置选项:
>
branch.master.remote
设置为 origin
branch.master.merge
设置为 refs / heads / master
基本上说 master
应该被视为您的 master
分支的默认上游分支。它们最明显的作用是在 master
时为 git pull
提供默认操作,但也可用于其他各种情况,比如在 git status
顶部提供有用的消息,告诉你 master
的位置是相比于 origin / master
。然而,这些设置是 not ,用于通知默认操作 git push
和 git push origin
>除非你还设置了配置选项 push.default
到跟踪
(或者上游
在最近的版本中)。
因此,作为非常近似的摘要,设置 remote。< name> ;. push 会影响
set config选项通常会影响 git push
的默认动作,而 git pull
的操作。
Question
What's the difference between:
$ git remote add origin git@github.com:yourname/yourproject.git
$ git config remote.origin.push refs/heads/master:refs/heads/master
$ git push
and:
$ git remote add origin git@github.com: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).
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, doing git 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:
git config remote.origin.push refs/heads/master:refs/heads/master
... you will find that git push origin
will just push master
to master
.
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
in origin
should be regarded as the default "upstream" branch of your master
branch. Their most obvious effect is to provide a default action for git pull
when you are on master
, but are also used in a variety of other situations, such as providing the helpful message at the top of git status
that tells you where master
is compared to origin/master
. These settings are not, however, used to inform the default action of git push
and git push origin
unless you have also set the config option push.default
to tracking
(or upstream
in recent versions).
So, as a very approximate summary, setting remote.<name>.push
affects the default action of git push
, while git push -u origin master
sets config options that usually just affect the action of git pull
.
这篇关于`git config`和`git push --set-upstream`有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!