git 本地仓库和远程服务器仓库没有一样的提交,用git pull出错

最近在一个小组里面搞协同开发,但是我搭建的git服务器配置好之后却遇到了一些奇怪的问题.困扰了我一段时间的就是gitpull没有默认的值的情况,在网上找到了很好的解决方法,现在放在这里…

gitpull的默认地址

当git clone之后,直接git pull它会自动匹配一个正确的remote url

是因为在config文件中配置了以下内容:

1
2
3
[branch "master"]
  remote = origin
  merge = refs/heads/master

表明:

  1. git处于master这个branch下时,默认的remote就是origin;
  2. 当在master这个brach下使用指定remote和merge的git pull时,使用默认的remote和merge。

但是对于自己建的项目,并用push到远程服务器上,并没有这块内容,需要自己配置。

如果直接运行git pull,会得到如此结果:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
$ git pull
Password:
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.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 "master" ]
remote = &lt;nickname&gt;
merge = &lt;remote-ref&gt;
  
[remote "<nickname>" ]
url = <url>
fetch = <refspec>
  
See git-config(1) for details.

在参考[2]中,有这样一段:

Note: at this point your repository is not setup to merge _from_ the remote branch when you type ‘git pull’. You can either freshly ‘clone’ the repository (see “Developer checkout” below), or configure your current repository this way:

1
2
3
git remote add -f origin login@git.sv.gnu.org: /srv/git/project .git
git config branch.master.remote origin
git config branch.master.merge refs /heads/master

因此通过git config进行如下配置:

1
2
$ git config branch.master.remote origin
$ git config branch.master.merge refs /heads/master

或者加上–global选项,对于全部项目都使用该配置。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值