Here you can use git branch -d since it will not remove any branch that has not yet been merged with your current branch:
git config --global alias.cleanup-branches \ '!git branch | grep -v "\*" | awk "{ print $1 }" | xargs git branch -d'
Just tried it locally and it worked, although it's a little scary to watch how it works.
source share