Track all remote git branches as local branches

前端 未结 15 2389
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 09:01

Tracking a single remote branch as a local branch is straightforward enough.

$ git checkout --track -b ${branch_name} origin/${branch_name}
<
15条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 09:49

    Using bash:

    after git 1.9.1
    for i in `git branch -a | grep remote | grep -v HEAD | grep -v master`; do git branch --track ${i#remotes/origin/} $i; done
    

    credits: Val Blant, elias, and Hugo

    before git 1.9.1

    Note: the following code if used in later versions of git (>v1.9.1) causes

    1. (bug) All created branches to track master
    2. (annoyance) All created local branch names to be prefixed with origin/
    for remote in `git branch -r `; do git branch --track $remote; done
    

    Update the branches, assuming there are no changes on your local tracking branches:

    for remote in `git branch -r `; do git checkout $remote ; git pull; done
    

    Ignore the ambiguous refname warnings, git seems to prefer the local branch as it should.

提交回复
热议问题