Created
July 31, 2012 18:40
-
-
Save trobrock/3219365 to your computer and use it in GitHub Desktop.
Clean unneeded branches from a git remote
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
#!/usr/bin/env bash | |
git_clean_remote() | |
{ | |
remote=$1 | |
[[ -z "$remote" ]] && echo "Must provide a remote" && return 1 | |
for branch in $(git branch -r | grep $remote | grep -v master) | |
do | |
diff=$(git cherry -v master $branch | wc -l) | |
short_branch=$(echo $branch | cut -d'/' -f2) | |
if [ "$diff" -eq 0 ]; then | |
git push $remote :$short_branch > /dev/null 2>&1 | |
git branch -d $short_branch > /dev/null 2>&1 | |
echo "Deleted branch $branch" | |
else | |
echo "Can't delete $branch" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment