Create alias manually in ~/.gitconfig
file (recommened):
[alias]
gone = "!f() { git fetch --all --prune; git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D; }; f"
Create alias (problematic):
git config --global alias.gone '!f() { git fetch --all --prune; git branch -vv | awk "/: gone]/{print $1}" | xargs git branch -D; }; f'
Usage:
git gone
Blog post:
This command doesn't always work as expected. For me the double quotes used on the awk command result in it printing the entire line from git branch. The solution is to swap the single/double quote usage and escape the variable expansion:
This was very obvious when I had a branch most recent commit that had "-P" in the commit message. This was being interpreted by
git branch -D
and raised an error.