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

后端 未结 30 1310
离开以前
离开以前 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:02

    kuboon's answer missed deleting branches which have the word master in the branch name. The following improves on his answer:

    git branch -r --merged | grep -v "origin/master$" | sed 's/\s*origin\///' | xargs -n 1 git push --delete origin
    

    Of course, it does not delete the "master" branch itself :)

提交回复
热议问题