Skip to content

Instantly share code, notes, and snippets.

@hasghari
Created January 13, 2013 16:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasghari/4525047 to your computer and use it in GitHub Desktop.
Save hasghari/4525047 to your computer and use it in GitHub Desktop.
shell script to cleanup local and remote repositories that have been merged
#!/bin/sh
# This has to be run from master
git checkout master
# Update our list of remotes
git fetch
# Delete stale remote-tracking branches
git remote prune origin
# Remove local fully merged branches
git branch --merged master | grep -v 'master$' | xargs git branch -d
# Show remote fully merged branches
echo "The following remote branches are fully merged and will be removed:"
git branch -r --merged master | grep -e '\s*origin' | sed 's/ *origin\///' | grep -v 'master$'
read -p "Continue (y/n)? "
if [ "$REPLY" == "y" ]
then
# Remove remote fully merged branches
git branch -r --merged master | grep -e '\s*origin' | 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