我将远程原点设置为当前分支的默认分支.我还有一个上游遥控器,它不是分支的默认值.有没有办法在远程配置默认分支,所以当我拉它默认为该分支?
这是我的.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
Run Code Online (Sandbox Code Playgroud)
有了这个我可以愉快地做以下,它默认为 origin/gh-pages
git pull
Run Code Online (Sandbox Code Playgroud)
我想做的就是给它远程上游并让它弄清楚分支(gh-pages)部分
git pull upstream
Run Code Online (Sandbox Code Playgroud)
而不是这个
git pull upstream gh-pages
Run Code Online (Sandbox Code Playgroud)
如果我省略分支,我现在得到以下内容:
$ 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.
Run Code Online (Sandbox Code Playgroud)
我可以看到三种不同的默认方式,在我目前的情况下对我有用,但我不知道如何做任何一个:):*只需使用当前分支作为远程上游的默认值*表示默认值当前分支的上游远程分支(同时将原始分支保留为默认分支)*表示远程分支上的默认分支.当然,如果我切换分支默认上游分支的危险保持不变.在我的情况下,这很好,但我可以看到那些没有想到它的人.
注意为远程指定git branch请求类似的问题,但解决方案需要执行我们不想做的两件事之一 - 更改默认远程或显式列出分支(我们希望这个编码以避免手动错误).
在 .git/config 中,您可以提供信息。例如,如果您在分支中foo并且想要远程拉取moo
[branch "foo"]
remote = origin
merge = refs/heads/moo
Run Code Online (Sandbox Code Playgroud)
下次您git pull在分支中运行时foo,它将从moo.
stackoverflow =>如何让 git 始终从特定分支拉取?