Git alias to remove deleted and merged branches. It works locally, with any specific remote or both.
Add the alias in the .gitconfig
file as specified below:
[alias]
autoremove = "!sh git-autoremove.sh"
autoremoveall = "!git remote | xargs -n 1 git autoremove; git autoremove"
Create the .git_autoremove.sh
file in the home folder (~ /) and add the contents of the file contained in this gist.
Add this to your path:
export PATH=$HOME/.git_autoremove.sh:$PATH
First of all, make sure to edit the whitelist
to match your own protected branches. Afterwards, go forth and clean up.
To delete local branches that have been deleted or merged:
git autoremove
To delete branches from a specific remote that have been deleted or merged:
git autoremove origin # or any other remote
Most often than not, you'll want to delete all deleted / merged branches, regardless if local or belonging to any remote:
git autoremoveall