Created
October 24, 2014 05:19
-
-
Save uasi/8d8966f18dcd4504f428 to your computer and use it in GitHub Desktop.
git prune-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/sh | |
# | |
# git-prune-branches - prune merged branches | |
# | |
# Configurations: | |
# .git/protected-branches - one-line regex matching the names of the branches to be protected. | |
# | |
if [ "`git branch | grep '^\*'`" != "* master" ]; then | |
echo "Error: not on master." | |
exit 1 | |
fi | |
protected_branches=$( cat "`git rev-parse --git-dir`/protected-branches" 2> /dev/null | head -n1 ) | |
protected_branches="${protected_branches}${protected_branches:+|}^master$" | |
echo "Deleting branches ignoring $protected_branches" | |
git branch --merged | cut -c3- | egrep -v "$protected_branches" | xargs git branch -d | |
git remote prune origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: