Since Git doesn't have a built in feature to delete multiple git branch in local project, deleting many branches in your local Git project might take you a while.
[email protected]:~/go/src/github.com/masgar/test$ git branch feat/api-create-product feat/api-delete-product feat/api-get-products feat/api-update-product * master
The common method is to delete one by one:
git branch -D feat/api-create-product git branch -D feat/api-delete-product git branch -D feat/api-get-product git branch -D feat/api-update-product
While it is easy to do in smaller number of branch, It might turned into disaster when there are too many branches to delete. Here is a tip on how to delete multiple git branches by a pattern quickly.
- Open a terminal, move to your Git project.
git branch | grep "<pattern>"to see list of git branch
- Type in
git branch | grep "<pattern>" | xargs git branch -D
Change the <pattern> with a regular expression(RegEx) that match your branch name. For example:
git branch | grep "feat" | xargs git branch -D or
git branch | grep "*" | xargs git branch -D
Credit to Raja Sekar Durairaj for posting Deleting Multiple Branches in Git in Medium