git新建本地分支自动与远程分支关联
Hello!
如果觉得不错的话,并且不吝转载时,请顺便添加上这篇文章的链接
http://www.hi-ruby.com/posts/1033
今天经过老大的指点,终于一解困惑我多年的这个问题:
使用git时候,本地新建分支, push到remote上去后,再次pull下来,会报以下提示:
You asked me to pull without telling me which branch you want to merge with, and 'branch.production.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 "production"] remote = <nickname> merge = <remote-ref> [remote "<nickname>"] url = <url> fetch = <refspec> See git-config(1) for details.
之前都是按照提示手动配置的,一直在寻找利用口令直接配置的方法,经过老大指点,问题轻松解决:
git branch --set-upstream production origin/production
结果是在项目目录下 .git/config中添加如下内容,也就是之前我一直手动添加的代码:
[branch "production"] remote = origin merge = refs/heads/production
man git branch如下:
When a local branch is started off a remote-tracking branch, git sets up the branch so that git pull will appropriately merge from the remote-tracking branch. This behavior may be changed via the global branch.autosetupmerge configuration flag. That setting can be overridden by using the --track and --no-track options, and changed later using git branch --set-upstream.