Track all remote git branches as local branches

前端 未结 15 2122
佛祖请我去吃肉
佛祖请我去吃肉 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:30

    The answer given by Otto is good, but all the created branches will have "origin/" as the start of the name. If you just want the last part (after the last /) to be your resulting branch names, use this:

    for remote in `git branch -r | grep -v /HEAD`; do git checkout --track $remote ; done
    

    It also has the benefit of not giving you any warnings about ambiguous refs.

提交回复
热议问题