git branch my_branch
推一下:
git push origin my_branch
现在假设有人在服务器上做了一些更改,我想要从
origin/my_branch
拉取代码。我执行以下操作:git pull
但是我得到:
You asked me to pull without telling me which branch you
want to merge with, and 'branch.my_branch.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "my_branch"]
remote = <nickname>
merge = <remote-ref>
[remote "<nickname>"]
url = <url>
fetch = <refspec>
See git-config(1) for details.
我了解到我可以让它运作起来的方法是:
git branch --set-upstream my_branch origin/my_branch
为什么我每次创建分支都需要这样做呢?难道不明显吗,如果我将
my_branch
推送到origin/my_branch
,那么我肯定想将origin/my_branch
拉取到my_branch
中。我怎样才能将此设置为默认行为呢?
branch.autosetupmerge
的默认设置意味着,当从远程跟踪分支(例如<remote-name>/<branch-name>
) 创建分支时,新分支的上游配置才会自动设置 (参见 git-config(1)). 你可能是从现有的本地分支创建分支。如果你要直接从远程分支的最新提交(尽管你在本地分支上)创建分支,则可以使用git branch my_branch <remote-name>/<branch-name>
自动设置上游配置。 - Chris Johnsen--set-upstream
选项已被弃用。应使用--track
或--set-upstream-to
代替。 - Sean the Bean--set-upstream
已经被弃用,那么Git开发者应该从帮助信息中移除它,这样当你在没有设置上游分支的情况下运行git push
时,就不会再显示该选项了。 - Christopher Huntergit branch --set-upstream
已经被废弃,git push --set-upstream
没有被废弃。 - Rag