为pull提供非默认远程的默认分支

时间:2011-09-17 17:50:28

标签: git github

我将远程原点设置为当前分支的默认分支。我还有一个上游遥控器,它不是分支的默认值。有没有办法在远程配置默认分支,所以当我拉它默认为该分支?

这是我的.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.

我可以看到三种不同的默认方式,在我目前的情况下对我有用,但我不确定如何做任何一种:):  *只需使用当前分支作为远程上游的默认分支  *指示当前分支的上游远程的默认分支(同时将原始分支保留为默认分支)  *表示遥控器上的默认分支。当然,如果我切换分支默认上游分支的危险保持不变。在我的情况下,这很好,但我可以看到那些没有想到它的人。

注意specifying git branch for remote提出了类似的问题,但解决方案需要做我们不想做的两件事之一 - 更改默认远程或明确列出分支(我们希望这个编码以避免手动错误)

1 个答案:

答案 0 :(得分:4)

在.git / config中,您可以提供信息。例如,如果您在分支foo中,并且想要从moo

远程提取
[branch "foo"]
   remote = origin
   merge = refs/heads/moo

下次在分支git pull中运行foo时,它将从moo开始。

stackoverflow =>中已经介绍过这个问题。 How do you get git to always pull from a specific branch?

相关问题