zoukankan      html  css  js  c++  java
  • git pull没有指定branch的报错

    执行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(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 "linux_c++"]
        remote = <nickname>
        merge = <remote-ref>
    
        [remote "<nickname>"]
        url = <url>
        fetch = <refspec>
    
    See git-config(1) 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上是有的。

  • 相关阅读:
    [No000088]并行循环vs普通循环
    [No000087]Linq排序,SortedList排序,二分法排序性能比较
    [No000086]C#foreach集合被改变,报错处理方案
    [No000085]C#反射Demo,通过类名(String)创建类实例,通过方法名(String)调用方法
    [No000084]C# 使用Log4Net(1)-快速建立一个demo
    [No000082]Convert和Parse的区别/Convert.ToInt32()与int.Parse()的区别
    [No000081]SVN学习笔记1-服务端搭建
    [No00007F]2016-面经[下] 英文简历写作技巧
    [No00007E]2016-面经[中]
    [No00007D]2016-面经[上]
  • 原文地址:https://www.cnblogs.com/minglee/p/9016554.html
Copyright © 2011-2022 走看看