To delete multiple Git branches at once, you can use the combination of git branch
, grep
, and xargs
commands. The git branch
command lists all local branches, grep -v master
filters out the master branch from the output, and xargs git branch -D
deletes each branch that matches the pattern.
Here's an example:
git branch | grep -v master | xargs git branch -D
This command will list all the Git branches, exclude the master branch, and then pass the remaining branch names to git branch -D
to delete them.
To make it more convenient, you can create an alias in your ~/.bashrc
or equivalent file:
alias delete_branches="git branch | grep -v master | xargs git branch -D"
After adding the alias, you can simply use the delete_branches
command to delete multiple branches at once.
Please note that deleting branches is a potentially destructive operation, so use it with caution and double-check before executing the command.