【发布时间】:2011-11-19 09:07:04
【问题描述】:
我将远程源设置为当前分支的默认分支。我还有一个上游遥控器,它不是分支的默认设置。有没有办法在遥控器上配置一个默认分支,所以当我拉它时默认到那个分支?
这是我的 .git/config:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:studgeek/knockout.git
[branch "gh-pages"]
remote = origin
merge = refs/heads/gh-pages
[remote "upstream"]
url = git://github.com/SteveSanderson/knockout.git
fetch = +refs/heads/*:refs/remotes/upstream/*
merge = refs/heads/gh-pages
有了这个我可以很高兴地做以下事情,它默认为origin/gh-pages
git pull
我想做的只是给它远程上游并让它找出分支(gh-pages)部分
git pull upstream
而不是这个
git pull upstream gh-pages
如果我省略分支,现在我会得到以下信息:
$ git pull upstream
You asked to pull from the remote 'upstream', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
我可以看到三种不同的默认方式,在我目前的情况下对我有用,但我不知道如何做任何一种:): * 只需使用当前分支作为远程上游的默认分支 * 为当前分支指明上游远程的默认分支(同时将 origin 保留为默认分支) * 表示遥控器上的默认分支。如果我切换分支,这里的危险当然是默认的上游分支保持不变。在我的情况下,这很好,但我可以看到那些没有预料到的燃烧的人。
注意specifying git branch for remote 提出了类似的问题,但解决方案需要做我们不想做的两件事之一 - 更改默认远程或显式列出分支(我们希望对此进行编码以避免手动错误)。
【问题讨论】: