Skip to content

Instantly share code, notes, and snippets.

@jovandeginste
Created November 12, 2015 13:49
Show Gist options
  • Save jovandeginste/983234ab83369481a971 to your computer and use it in GitHub Desktop.
Save jovandeginste/983234ab83369481a971 to your computer and use it in GitHub Desktop.
#!/bin/bash
: ${REMOTE:=origin}
set -x
git remote update $REMOTE --prune
set +x
TO_DELETE=$(diff <(git branch | cut -c 3-) <(git branch -r | cut -c 3- | grep $REMOTE | sed "s%^$REMOTE/%%") | grep '<' | awk '{print $2}')
if [[ -z "$TO_DELETE" ]]
then
echo "No local branches to delete."
exit
fi
echo "Deleting these (local) branches: $TO_DELETE"
echo "Press enter to continue"
read
for B in $TO_DELETE
do
git branch -d $B
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment