-
-
Save nook-ru/ac5e8f76797a02a749fb6282230a4177 to your computer and use it in GitHub Desktop.
Clean up old git branches
This file contains hidden or 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
#!/bin/bash | |
# 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$' | grep -v 'dev$' | 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$' | grep -v 'dev$' | |
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$' | grep -v 'dev$' | xargs -I% git push origin :% | |
echo "Done!" | |
echo "Obsolete branches are removed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment