Track all remote git branches as local branches

前端 未结 15 2303
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  Happy的楠姐
    2020-11-22 09:29

    In case you already have some branches checked out and want to

    • check out all remaining branches from the remote
    • make sure all local branches track the remote branches

    you can use the following bash- and zsh-compatible script:

    git branch -r | while read b; do if git branch | grep -q " ${b##*/}$"; then git branch --set-upstream ${b##*/} $b; else git branch --track ${b##*/} $b; fi; done
    

提交回复
热议问题