Skip to content

Instantly share code, notes, and snippets.

@aloverso
Created May 31, 2019 16:48
Show Gist options
  • Save aloverso/b35638f39c6d8e7543a266ccd126f885 to your computer and use it in GitHub Desktop.
Save aloverso/b35638f39c6d8e7543a266ccd126f885 to your computer and use it in GitHub Desktop.
Delete merged git branches
#!/usr/bin/env bash
git checkout master
git fetch -p
echo ""
echo "THIS SCRIPT WILL DELETE THESE BRANCHES:"
echo "---------------------------------------"
git branch --merged master | grep -v "\*"
echo ""
echo -n "Do you want to proceed (y/n)?"
read answer
if echo "$answer" | grep -iq "^y" ;then
git branch --merged master | grep -v "\*" | xargs -n 1 git push --delete origin
git branch --merged master | grep -v "\*" | xargs -n 1 git branch -d
echo ""
echo "Enjoy your new cleanliness!"
else
echo ""
echo "Fine, clean it yourself"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment