最近在使用 Git 遇到一个从来没有遇到过的问题,同事修改了 GitLab 的项目代码,我帮忙同步到服务器,我直接一个 git pull 命令以为就可以,结果过了一天发现服务器上的项目代码并没有更新。

1、报错信息

  1. $ git pull
  2. Password:
  3. You asked me to pull without telling me which branch you
  4. want to merge with, and 'branch.master.merge' in
  5. your configuration file does not tell me, either. Please
  6. specify which branch you want to use on the command line and
  7. try again (e.g. 'git pull <repository> <refspec>').
  8. See git-pull(1) for details.
  9. If you often merge with the same branch, you may want to
  10. use something like the following in your configuration file:
  11. [branch "master"]
  12. remote = <nickname>
  13. merge = <remote-ref>
  14. [remote "<nickname>"]
  15. url = <url>
  16. fetch = <refspec>
  17. See git-config(1) for details.

2、解决办法

  1. $ git remote add -f origin 项目地址
  2. $ git config branch.master.remote origin
  3. $ git config branch.master.merge refs/heads/master

3、参考文档