Skip to content

Instantly share code, notes, and snippets.

@biliboss
Forked from macmladen/git-merged-remove.sh
Last active November 28, 2016 16:48
Show Gist options
  • Save biliboss/c2755e7c8d5f98fb5b35 to your computer and use it in GitHub Desktop.
Save biliboss/c2755e7c8d5f98fb5b35 to your computer and use it in GitHub Desktop.
Remove merged remote branches in repository.
#!/bin/sh
# Taken from and modified
# http://devblog.springest.com/a-script-to-remove-old-git-branches/
echo "The following remote branches are fully merged into master and will be removed:"
git branch -r --merged master | 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 | sed 's/ *origin\///' | grep -v 'master$' | xargs -I % git push origin --delete %
echo "Done!"
# Mac only: say “Obsolete branches are removed”
fi
# to remove your local branches that were removed from remote
# git remote prune origin
git branch --merged | grep -v "(^\*|master|dev)" | xargs git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment