Git pull-使用-u选项的默认远程和分支-与push一起使用但不与pull一起使用 [英] Git pull - default remote and branch using -u option - works with push but not pull
问题描述
我使用的是Git 2.6.3版,并且在运行时会收到此消息
I am on Git version 2.6.3, and get this message when just running
git pull
当前分支没有跟踪信息."
"There is no tracking information for the current branch."
给我的印象是git将默认为origin,并且在简单"配置下具有相同名称的分支.
I was under the impression that git would default to origin and the branch with the same name under the "simple" config.
遇到一些麻烦之后,我发现配置此配置的最简单方法是使用-u选项,如下所示:
After some trouble, I discover that the easiest way to configure this is to use the -u option like so:
$ git push -u origin master
然后它会说:
分支母版已设置为从源头跟踪远程分支母版."
"Branch master set up to track remote branch master from origin."
所以我的问题是,为什么我们不能在git pull中使用-u选项?
so my question is, why can't we use the -u option with git pull?
$ git pull -u origin master
-u
选项在拉动时无法识别,仅在推入时
the -u
option is not recognized on pull, only with push
我的问题是-是否有充分的理由?
my question is - is there a good reason for that?
推荐答案
您可以使用此命令设置当前分支的上游
$ git branch --set-upstream-to=origin/master
You can use this command to set the upstream of your current branch
$ git branch --set-upstream-to=origin/master
通过这种方式,您在拉动和推入时无需实际使用push
或pull
命令即可将上游分支默认设置为master.
This way your setting the upstream branch to master by default when pulling and pushing without actually using a push
or pull
command.
现在尝试git pull
,它应该开始从您的存储库中收集所有内容,然后它将显示为Already up-to-date
Now try to git pull
and it should start gathering everything from your repository and after that it will say it's Already up-to-date
如果您还有其他问题,我们将很乐意为您提供帮助.
If you have any further questions, I'll be happy to assist.
这篇关于Git pull-使用-u选项的默认远程和分支-与push一起使用但不与pull一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!