TL; DR:我有一个"跟踪"的分支,我不能拉.
所以我在这里"斗4":
$ git branch -v
bucket-1 410f7b5 * gh-53 * gh-48 * "Share App"
bucket-2 7ed70a2 * upgrade to SOLR 3.3.0
bucket-3 400ffe4 * emergency fix prod issue
* bucket-4 64c2414 Merge branch 'bucket-3' into bucket-4
master 8dc4854 [ahead 1] * gh-73
Run Code Online (Sandbox Code Playgroud)
我想从我的遥控器中提取更改:
$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.bucket-4.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "bucket-4"]
remote = <nickname>
merge = <remote-ref>
[remote "<nickname>"]
url = <url>
fetch = <refspec>
See git-config(1) for details.
Run Code Online (Sandbox Code Playgroud)
嗯,奇怪,我以为我已经添加了"bucket-4"作为跟踪分支.让我们来看看:
$ git remote show origin
* remote origin
Fetch URL: git@github.com:abcd/main.git
Push URL: git@github.com:abcd/main.git
HEAD branch (remote HEAD is ambiguous, may be one of the following):
bucket-3
master
Remote branches:
bucket-1 tracked
bucket-2 tracked
bucket-3 tracked
bucket-4 tracked
master tracked
Local branches configured for 'git pull':
bucket-1 merges with remote bucket-1
bucket-2 merges with remote bucket-2
bucket-3 merges with remote bucket-3
master merges with remote master
Local refs configured for 'git push':
bucket-1 pushes to bucket-1 (up to date)
bucket-2 pushes to bucket-2 (up to date)
bucket-3 pushes to bucket-3 (up to date)
bucket-4 pushes to bucket-4 (local out of date)
master pushes to master (fast-forwardable)
Run Code Online (Sandbox Code Playgroud)
实际上,bucket-4被标记为"已跟踪",但不知何故,它被配置为推送,但不是拉动.
看看我的.git/config文件,我看到我的大多数分支机构都有"远程"和"合并"条目,但对于bucket-4则没有.如果没有这个,它甚至被认为是"跟踪"的?
[remote "origin"]
url = git@github.com:abcd/main.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "rel-2011-07-07"]
remote = origin
merge = refs/heads/rel-2011-07-07
[branch "bucket-1"]
remote = origin
merge = refs/heads/bucket-1
[branch "bucket-2"]
remote = origin
merge = refs/heads/bucket-2
[branch]
autosetupmerge = true
[branch "bucket-3"]
remote = origin
merge = refs/heads/bucket-3
Run Code Online (Sandbox Code Playgroud)
我看到这里可能的解决方案是remote/merge在我的配置文件中添加bucket-4的条目.但如果没有这个被认为是"跟踪"的呢?bucket-4是在本地创建的,然后从这个repo推送到服务器,所以我怀疑我没有为这个分支正确设置跟踪.
我可以添加一些配置,以便将来所有本地分支都能正确跟踪其遥控器吗?
Mar*_*air 188
它bucket-4 pushes to bucket-4只是因为推送分支时的默认设置是将其推送到遥控器上具有匹配名称的分支.(请注意,这仍然是默认设置,即使本地分支正在跟踪远程跟踪分支,并且远程跟踪分支对应于远程存储库中具有不同名称的分支.)
设置你之间的关联最简单的方法bucket-4,并bucket-4在origin是确保在下次推的时候,你这样做:
git push -u origin bucket-4
Run Code Online (Sandbox Code Playgroud)
或者,你可以这样做:
git branch --set-upstream-to origin/bucket-4
Run Code Online (Sandbox Code Playgroud)
直接回答几个问题:
如果没有这个,它甚至被认为是"跟踪"的?
在这种情况下它不是 - 如果没有branch.bucket-4.merge或branch.bucket-4.remote在你的git配置中,它不会在任何意义上跟踪远程跟踪分支.输出git remote show origin只显示默认情况下推送分支的位置.
我可以添加一些配置,以便将来所有本地分支都能正确跟踪其遥控器吗?
我不认为有.当你在bucket-4本地创建时,正如我所假设的那样,远程跟踪分支不存在,因此无法在那时进行设置 - 这将是非常混乱的默认行为.您只需要记住将-u第一个git push分支添加到其上游存储库.
我希望有一些帮助.
小智 6
git branch --set-upstream <branch> origin/<branch> 至少从1.8.2.3(我的版本)开始不推荐使用。
使用git branch --set-upstream-to=origin/<branch> <branch>代替。