执行git pull或者git push的时,有时候会出现如下报错:

$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.linux_c++.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() for details. If you often merge with the same branch, you may want to
use something like the following in your configuration file: [branch "linux_c++"]
remote = <nickname>
merge = <remote-ref> [remote "<nickname>"]
url = <url>
fetch = <refspec> See git-config() for details.

我们先来看看当前分支状态:

$ git branch -av
* linux_c++ 584efea add cscope and fix fileencoding problam
master ee9d037 v1.0.1: add install.sh
remotes/origin/HEAD -> origin/master
remotes/origin/linux_c++ 584efea add cscope and fix fileencoding problam
remotes/origin/master ee9d037 v1.0.1: add install.sh

当前所在的linux_c++分支虽然与远程linux_c++同名,但实际上,这个分支并不是origin/linux_c++分支的追踪分支,所以当直接用git pull去请求拉新分支的时候,git并不知道应该拉取哪个分支。

因此,解决此问题有两个方案,一个是git pull或者git push的时候,指定相应的远程分支名,如:

$ git pull origin linux_c++

另一个方案则是,设置当前分支追踪某个远程分支。设置现有分支追踪远程分支的方式有两种:

git branch -u remote-name/branch_name branch_name

或者

git branch --set-upstream-to=remote_name/branch_name branch_name

当然,还可以再创建本地分支的时候,直接使其追踪到远程分支:

git checkout -b local_branch remote_name/remote_branch

当前我们的分支是已有分支,那么可以输入:

$ git branch -u origin/linux_c++ linux_c++
Branch linux_c++ set up to track remote branch linux_c++ from origin.

应当注意的一点是:git branch -u 和git branch --set-upstream-to 的两个选项都是要在较高的git版本才有,至少博主在1.7.1上发现没有这两个选项,而1.8.3.1上是有的。

最新文章

  1. IOS开发基础知识--碎片40
  2. QT TCP文件上传服务器
  3. poj 1050 To the Max
  4. 网站提供的下载IE8很慢 由于Microsoft 联机服务暂时不可用,SmartScreen筛选器无法检查此网站。
  5. Python中的split()函数的使用方法
  6. systemtap分析软raid io拆分问题
  7. CSSREM插件
  8. c语言中malloc realloc 和calloc的联系与区别
  9. swift中JSon数据的处理
  10. WINDOWS系统注册表取得管理权限研究
  11. LeetCode之“树”:Sum Root to Leaf Numbers
  12. SQLite异常 qAdmin: Cannot perform this operation on a closed dataset.【申明:来源于网络】
  13. R语言学习——向量
  14. nginx日志 logrotate配置
  15. 深入path类
  16. 洛谷 P4345 [SHOI2015]超能粒子炮&#183;改 解题报告
  17. 外显子分析报错解决方案bin field of BAM record does not equal value computed based on alignment start and end, and length of sequence to which read is aligned
  18. Phone漂亮的动画
  19. phantomhs获取网页的高度
  20. 设计模式-单例模式(Singleton Pattren)(饿汉模式和懒汉模式)

热门文章

  1. python中的list和array的不同之处 2
  2. C语言基础一
  3. InputStream与String,Byte之间互转
  4. c++primer 第四章编程练习答案
  5. python--pycharm汉化
  6. ps6-图层基础与操作技巧
  7. BEC translation exercise 7
  8. url字符串中含中文的转码方法
  9. mysql触发器与hash索引
  10. 关于nginx做代理,uwsgi gunicorn等服务器做后端时