Home > Mobile >  Git : How to delete all local branches (merged or not), except master and develop
Git : How to delete all local branches (merged or not), except master and develop

Time:12-03

I want to clean my local branches (merged or not), except master and 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...).

CodePudding user response:

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 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).

  • Related