[英]Git : How to delete all local branches (merged or not), except master and develop
I want to clean my local branches (merged or not), except master
and develop
.我想清理我的本地分支(合并与否),除了
master
和develop
。
I did some cleanup on the remote repository and I want to have the same locally.我对远程存储库进行了一些清理,我想在本地进行相同的清理。
I tried git fetch --prune
which removed some, but there is still a large amount (over a hundred...).我试过
git fetch --prune
删除了一些,但仍有大量(超过一百......)。
I'm not aware of a way to do this in git out of the box, but this can done with some shell scripting:我不知道在开箱即用的 git 中执行此操作的方法,但这可以通过一些 shell 脚本来完成:
git branch | grep -v master | grep -v develop | xargs git branch -D
Just make sure you are checked out to master
or develop
before you start, or this script will also attempt to drop the branch you're currently checked out to (and fail to do so, of course).只需确保您在
develop
之前已签出master
或 development,否则此脚本还将尝试删除您当前签出到的分支(当然不会这样做)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.