Created
July 15, 2012 19:07
-
-
Save harley/3118186 to your computer and use it in GitHub Desktop.
remove old branches that have been merged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adapted from http://devblog.springest.com/a-script-to-remove-old-git-branches | |
# This has to be run from master | |
git checkout master | |
# Update our list of remotes | |
git fetch | |
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 | 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 :% | |
echo "Done!" | |
say "Obsolete branches are removed" | |
fi | |
# OR if we wanna confirm it per branch: | |
# List dist branch merged | exclude master, HEAD and develop | remove origin/ | delete remote branch asking confirmation | |
# Assume you don't wanna remove 'develop' branch (for people using gitflow) | |
git branch -r --merged | grep -vw "master" | grep -vw "HEAD" | grep -vw "develop" | cut -d "/" -f2 | xargs -p -I {} git push origin :{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment