How can I delete all Git branches which have been merged?

后端 未结 30 1086
离开以前
离开以前 2020-11-22 14:22

I have many Git branches. How do I delete branches which have already been merged? Is there an easy way to delete them all instead of deleting them one by one?

30条回答
  •  忘了有多久
    2020-11-22 15:06

    If you'd like to delete all local branches that are already merged in to the branch that you are currently on, then I've come up with a safe command to do so, based on earlier answers:

    git branch --merged | grep -v \* | grep -v '^\s*master$' | xargs -t -n 1 git branch -d
    

    This command will not affect your current branch or your master branch. It will also tell you what it's doing before it does it, using the -t flag of xargs.

提交回复
热议问题