How to fetch all Git branches

后端 未结 30 1596
情书的邮戳
情书的邮戳 2020-11-22 09:38

I cloned a Git repository, which contains about five branches. However, when I do git branch I only see one of them:

$ git branch
* master
         


        
30条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 09:59

    You will need to create local branches tracking remote branches.

    Assuming that you've got only one remote called origin, this snippet will create local branches for all remote tracking ones:

    for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
    

    After that, git fetch --all will update all local copies of remote branches.

    Also, git pull --all will update your local tracking branches, but depending on your local commits and how the 'merge' configure option is set it might create a merge commit, fast-forward or fail.

提交回复
热议问题