“Cannot update paths and switch to branch at the same time”

前端 未结 11 1680
广开言路
广开言路 2020-12-02 04:24

I sometimes use the checkout -b option to create a new branch, check it out at the same time and set up tracking in one command.

In a new environment, I

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 05:22

    You can get this error in the context of, e.g. a Travis build that, by default, checks code out with git clone --depth=50 --branch=master. To the best of my knowledge, you can control --depth via .travis.yml but not the --branch. Since that results in only a single branch being tracked by the remote, you need to independently update the remote to track the desired remote's refs.

    Before:

    $ git branch -a
    * master
    remotes/origin/HEAD -> origin/master
    remotes/origin/master
    

    The fix:

    $ git remote set-branches --add origin branch-1
    $ git remote set-branches --add origin branch-2
    $ git fetch
    

    After:

    $ git branch -a
    * master
    remotes/origin/HEAD -> origin/master
    remotes/origin/branch-1
    remotes/origin/branch-2
    remotes/origin/master
    

提交回复
热议问题