The following code does the following:
- Get every branch name
- Loop over the values
- Skip the branch named master
- Delete the branch without force
Run this code to setup the alias:
Code:
$ git config --global alias.cleanup '!git for-each-ref --format="%(refname:short)" refs/heads | grep -v 'master' | xargs git branch -d'
And this is how to use the alias:
Essentially the alias is used to delete any branches that are up-to-date, not master, and not the currently checked out branch. I created this alias because it makes the list much easier to reach when calling $ git branch. I hope you get find it useful!