Git: 删除所有本地分支(branch) 并保留指定分支

git的本地分支建得多了不好管理。

可以在bash里面运行这句命令来删除所有本地分支,同时指定保留一个分支:

git branch | grep -v "你要保留的分支名" | xargs git branch -D

比如你要删除所有的分支只保留master:

git branch | grep -v "master" | xargs git branch -D

如果你每次都想删除所有分支只保留master,那么可以使用alias来简化命令,比如这样:

alias gbr="git branch | grep -v "master" | xargs git branch -D"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.