Sometimes, deleting branches that we are no longer working on can be tedious. For this, you can create an alias to do the hard work for you.
All git aliases are located at the ~/.gitconfig
file:
...
[alias]
cm = commit # Example alias
The custom alias we will create will delete all branches except master and the current one:
git branch | grep -v "master" | grep -v "^*" | xargs git branch -d
At ~/.gitconfig
:
...
[alias]
del-branches = !git branch | grep -v "master" | grep -v "^*" | xargs git branch -d
Finally, you just have to call the alias at your repository directory as a normal git command:
git del-branches
Top comments (1)
Nice tip.
I have similar commands/aliases for deleting merged branches.
Checkout git-extras for more, fun git commands/aliases.