Can I delete all the local branches except the current one?

后端 未结 14 2445
广开言路
广开言路 2020-12-12 13:07

I want to delete all branches that get listed in the output of ...

$ git branch

... but keeping current branch, in one step. Is th

14条回答
  •  情歌与酒
    2020-12-12 13:17

    I use this because I get to be more selective in what I do not want to delete. This below command removes every branch except master, develop and the current branch.

    BRANCHES=$(git branch | egrep -v "(master|develop|\*)" | xargs git branch -D)
    echo $BRANCHES
    

    So I put this in my ~/.zshrc

    delete_branches() {
      BRANCHES=$(git branch | egrep -v "(master|develop|\*)" | xargs git branch -D)
      echo $BRANCHES
    }
    
    alias cleanup_branches=delete_branches
    

提交回复
热议问题