Delete local Git branches after deleting them on the remote repo

前端 未结 12 1961
死守一世寂寞
死守一世寂寞 2020-11-30 16:26

I want to have my local and remote repositories always in sync in terms of branches.

After a Pull Request review on GitHub, I merge and remove my branch there (remot

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 17:04

    I've written this one-liner to list all local branches which do not have corresponding remote branch:

    diff -u <(git branch|sed 's/..//') <(git branch -r|sed 's/..origin\///')|tail -n +4|sed -n "s/^-//p" -
    

    After this done, deleting these local branches is easy with xargs:

    diff -u <(git branch|sed 's/..//') <(git branch -r|sed 's/..origin\///')|tail -n +4|sed -n "s/^-//p" -|xargs -r git branch -d
    

提交回复
热议问题