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

  • 相关阅读:
    C++ 模板实现约瑟夫环
    C++实现向文件输出对象并读取对象
    C++实现对本地文件加行号并输出到本地文件
    C++ vector动态容量变化
    C++纯虚函数应用实例
    华为2016研发工程师-删数字
    iOS-宫格拼图
    iOS-审核4.3入坑(已出坑)
    Mac-关闭Mac电脑启动声音(咚~)
    彻底完全卸载SQL Server 2005教程
  • 原文地址:https://www.cnblogs.com/minglee/p/9016554.html
Copyright © 2020-2023  润新知