git新建本地分支自动与远程分支关联

Hello! 如果觉得不错的话,并且不吝转载时, 请顺便添加上这篇文章的链接http://www.hi-ruby.com/articles/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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值