Cleaning up local branches

Koen van Gilst

Koen van Gilst / February 10, 2022

1 min read

git branch -vv | grep ': gone]'|  grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -d

Useful for cleaning up a local repository with lots of stale branches. The script can also be used with the -D flag (instead of -d). This will delete all local branches, even if they have any unmerged changes.