Skip to content

Instantly share code, notes, and snippets.

@getfatday
Created September 22, 2017 20:38
Show Gist options
  • Save getfatday/27aa19f9acff1fe963f1840b78bb23f4 to your computer and use it in GitHub Desktop.
Save getfatday/27aa19f9acff1fe963f1840b78bb23f4 to your computer and use it in GitHub Desktop.
Remove unused local branches
#!/usr/bin/env bash
usage()
{
echo "usage: git unused [-D]"
}
while getopts "hD" opt; do
case $opt in
h)
usage
exit 1
;;
D)
DELETE="1"
;;
\?)
usage
exit 1
;;
esac
done
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | while read branch; do
if [ ! -z "$DELETE" ]; then
git branch -D $branch
else
echo Would remove $branch
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment