执行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上是有的。

git pull没有指定branch的报错的更多相关文章

  1. Git上传代码遇到的报错

    Git上传代码遇到的报错 1.git上传代码卡住(Total 7072 (delta 2508), reused 6844 (delta 2376), pack-reused 0) git confi ...

  2. [Git] 拉开发分支的代码报错

    Git拉开发分支的代码报错: fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed ...

  3. git删除本地分支失败,报错error: branch 'test219' not found.

    错误: 删除本地分支报错,操作如下: git branch -d test219 操作失败,错误信息:error: branch 'test219' not found git branch -D t ...

  4. git上传到版本库报错:Pull is not possible because you have unmerged files(已解决)

    问题所在:操作次数太多,第一次报错之删掉了.git并没有删除下面两个文件 才报了题述错误. 解决办法: 将这三个文件都删除在重新运行所有指令.

  5. git 本地推送远程仓库报错: error: failed to push some refs to 'https://github.com/yangtuothink/mxonline.git'

    报错现象 添加远程仓库后 推送代码的时候报错 报错分析 远程代码和本地代码不匹配问题 远程初始仓库的创建有些默认 的 README什么的本地是没有的 需要先同步后再上传 报错解决 git push - ...

  6. git提交待审核代码,报错没有change-id的解决方法

    git提交是报错没有change-id的解决方法: 1.先仔细查看报错内容,查出是哪天提交记录缺少change-id 2.如果是最近的一条缺少,则直接执行git commit --amend &quo ...

  7. git拉代码,IntelliJ idea报错,cannot load module xxxxx

    1 从git上下工程的时候,IntelliJ idea报错,cannot load module xxxx VCS-git-clone-ssh:xxxx ,报错cannot load module x ...

  8. git fatal: remote origin already exists. 报错解决

    在研究git的时候,随便输了个 git remote add origin xxx; 然后再真正add 远程仓库的时候,报了git fatal: remote origin already exist ...

  9. git 生成密匙时遇到报错 :Too many arguments.

    今天在我用新电脑想要向github上的远程库上传项目时,由于新电脑上的本地库没有与远程库建立连接,所以要在本地生成密匙添加到github上才可以上传,在我执行命令 ssh-keygen -t rsa- ...

随机推荐

  1. js 图片加载失败处理方法

    在项目中不可避免会用到图片,尤其是列表,有时候图片会加载失败:这样就会显示一个很难看的坏图片缩略图:下面介绍两种方法,解决这个问题: 1.如果在你的项目中有引入jQuery插件,你可以使用error( ...

  2. Mac上的抓包工具Charles[转载]

    今天就来看一下Mac上如何进行抓包,之前有一篇文章介绍了使用Fidder进行抓包 http://blog.csdn.net/jiangwei0910410003/article/details/198 ...

  3. GridView的简单使用

    测试代码: activity_main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/a ...

  4. LeetCode Reverse String II

    原题链接在这里:https://leetcode.com/problems/reverse-string-ii/#/description 题目: Given a string and an inte ...

  5. Real-Time Rendering (2) - 变换和矩阵(Transforms and Matrics)

    http://blog.csdn.net/silangquan/article/details/9970673 提要 在图形的计算中,比如旋转.缩放.平移.投影等操作,矩阵都扮演着极其重要的角色,它是 ...

  6. 记一次内存溢出的分析经历——使用thrift

    背景: 有一个项目做一个系统,分客户端和服务端,客户端用c++写的,用来收集信息然后传给服务端(客户端的数量还是比较多的,正常的有几千个), 服务端用Java写的(带管理页面),属于RPC模式,中间的 ...

  7. 5、Selenium+Python自动登录163邮箱发送邮件

    1.Selenium实现自动化,需要定位元素,以下查看163邮箱的登录元素 (1)登录(定位到登录框,登录框是一个iframe,如果没有定位到iframe,是无法定位到账号框与密码框) 定位到邮箱框( ...

  8. redis client API-----------python

    想知道redis针对各种编程语言推荐的接口API实现,请参考http://redis.io/clients/ 选择python语言,则使用https://github.com/andymccurdy/ ...

  9. [C++] 动态规划之矩阵连乘、最长公共子序列、最大子段和、最长单调递增子序列、0-1背包

    一.动态规划的基本思想 动态规划算法通常用于求解具有某种最优性质的问题.在这类问题中,可能会有许多可行解.每一个解都对应于一个值,我们希望找到具有最优值的解. 将待求解问题分解成若干个子问题,先求解子 ...

  10. java代码I/O类

    总结:流类无法理解啊—————— package com.aini; import java.io.*; //流类 //使用FileInputStream读取文件信息 public class ffg ...