指定一个非默认远程进行拉取的默认分支 [英] specify default branch for a non-default remote for pull
问题描述
我将远程原点设置为当前分支的默认分支。我也有一个上游远程,这不是分支的默认设置。有没有一种方法来配置远程的默认分支,所以当我把它拉到默认分支?
这是我的.git / config:
[remoteorigin]
fetch = + refs / heads / *:refs / remotes / origin / *
url = git@github.com:studgeek / knockout.git
[branchgh-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上游gh-pages
正确现在,如果我省略了分支,我会得到以下内容:
$ git pull upstream
您要求从远程'upstream',但没有指定
a分支。因为这不是您当前分支的默认配置远程
,所以您必须在命令行上指定一个分支。
我可以看到三种不同的违约方式,在我目前的情况下, m不知道如何做任何:) :)
*只需使用当前分支作为远程上游的默认值
*指示当前分支的上游远程的默认分支(在离开原点的同时)默认分支)
*指示远程的默认分支。当然,如果我切换分支,默认的上游分支保持不变。在我的情况下,这将是很好,但我可以看到那些没有预料到它的燃烧的人。
注意指定远程的git分支会提出类似的问题,但解决方案需要执行两件我们不想做的事情之一 - 更改默认值远程或明确列出分支(我们希望这样编码以避免手动错误)。
在.git / config中,您可以提供信息。例如,如果您在分支 foo
中并且您想从 moo
[branchfoo]
remote = origin
merge = refs / heads / moo
下次在分支 foo $ c中运行
git pull
$ c>,它会从 moo
。
中拉出来,这已经在stackoverflow => 你如何让git总是从一个特定的分支?
I have the remote origin set as the default branch for my current branch. I also have an upstream remote which is not the default for the branch. Is there a way to configure a default branch on the remote so when I pull it defaults to that branch?
Here is my .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
With this I can happily do the following and it defaults to origin/gh-pages
git pull
What I would like to do is just give it the remote upstream and have it figure out the branch (gh-pages) part so
git pull upstream
rather than this
git pull upstream gh-pages
Right now I get the following if I omit the branch:
$ 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.
I can see three different ways of defaulting that would work for me in my current situations, but I'm not sure how to do any of them :): * Just use the current branch as the default on the remote upstream * Indicate a default branch for the upstream remote for the current branch (while leaving origin the default branch) * Indicate a default branch on the remote. The danger here of course if I switch branches the default upstream branch stays the same. In my case that would be fine, but I can see that burning folks who didn't expect it.
Note specifying git branch for remote asks a similar question, but the solution requires doing one of two things we don't want to do - changing the default remote or explicitly listing the branch (we want this codified to avoid manual error).
In the .git/config, you can supply the information. Example if you are in branch foo
and you want to pull remotely from moo
[branch "foo"]
remote = origin
merge = refs/heads/moo
Next time you run git pull
in branch foo
, it will pull from moo
.
This has been covered in stackoverflow => How do you get git to always pull from a specific branch?
这篇关于指定一个非默认远程进行拉取的默认分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!