Skip to content

Instantly share code, notes, and snippets.

@Crash--
Created May 26, 2012 09:44
Show Gist options
  • Save Crash--/2793164 to your computer and use it in GitHub Desktop.
Save Crash--/2793164 to your computer and use it in GitHub Desktop.
Remove all merged branch. Be careful if you have merged a branch into the master and continue to work on it and then you haven't merged it yet, this script will remove it.
git checkout master
git fetch
git remote prune origin
#Remove locally
git branch --merged master | grep -v 'master$' | xargs git branch -d
echo "Branches merged, to delete:"
git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$'
read -p "Sure about that (y/n)? "
if [ "$REPLY" == "y" ]
then
#Remove remotely
git branch -r --merged master | sed 's/ *origin\///' \
| grep -v 'master$' | xargs -I% git push origin :%
echo "Done!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment