Skip to content

Instantly share code, notes, and snippets.

@sod
Last active July 25, 2018 09:50
Show Gist options
  • Save sod/d177620602d483bccfc28fe7251bf0f2 to your computer and use it in GitHub Desktop.
Save sod/d177620602d483bccfc28fe7251bf0f2 to your computer and use it in GitHub Desktop.
#!/bin/bash
git fetch -p
CURRENT=`git rev-parse --abbrev-ref HEAD`
if [ "$CURRENT" != "master" ]; then
git checkout master
fi
GONE=`git branch -vv | grep ": gone]" | awk '{print $1}'`
MERGED=`git branch --merge | grep -v '^*'`
echo
if [ "$GONE" != "" ]; then
echo "Delete GONE:"
echo
echo "$GONE"
fi
if [ "$MERGED" != "" ]; then
echo "Delete MERGED:"
echo
echo "$MERGED"
fi
if [ "$GONE" == "" ]; then
echo "Nothing to clean"
echo
exit 0
fi
echo
echo "Continue?"
read
if [ "$MERGED" != "" ]; then
for branch in "$MERGED"; do
git branch -D $branch
done
fi
if [ "$GONE" != "" ]; then
for branch in "$GONE"; do
git branch -D $branch
done
fi
if [ "$CURRENT" != "master" ]; then
git checkout "$CURRENT"
fi
echo
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment