我将远程源设置为我当前分支的默认分支。我还有一个上游 Remote ,它不是分支的默认设置。有没有办法在 Remote 上配置一个默认分支,这样当我 pull 它时默认到那个分支?
这是我的 .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问一个类似的问题,但解决方案需要做我们不想做的两件事之一 - 更改默认 Remote 或明确列出分支(我们希望将其编码以避免手动错误)。
最佳答案
在 .git/config 中,您可以提供信息。例如,如果你在分支 foo
中并且你想从 moo
[branch "foo"]
remote = origin
merge = refs/heads/moo
下次您在分支 foo
中运行 git pull
时,它将从 moo
pull 。
这已在 stackoverflow 中介绍 => How do you get git to always pull from a specific branch?
关于git - 为 pull 的非默认远程指定默认分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7456709/