Created
July 18, 2014 13:07
-
-
Save cbartlett/ad09c2d63224fd2759c5 to your computer and use it in GitHub Desktop.
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 | |
clean() | |
{ | |
REMOTES="$@"; | |
if [ -z "$REMOTES" ]; then | |
REMOTES=$(git remote); | |
fi | |
REMOTES=$(echo "$REMOTES" | xargs -n1 echo) | |
RBRANCHES=() | |
while read REMOTE; do | |
CURRBRANCHES=($(git ls-remote $REMOTE | awk '{print $2}' | grep 'refs/heads/' | sed 's:refs/heads/::')) | |
RBRANCHES=("${CURRBRANCHES[@]}" "${RBRANCHES[@]}") | |
done < <(echo "$REMOTES" ) | |
[[ $RBRANCHES ]] || exit | |
LBRANCHES=($(git branch | sed 's:\*::' | awk '{print $1}')) | |
for i in "${LBRANCHES[@]}"; do | |
skip= | |
for j in "${RBRANCHES[@]}"; do | |
[[ $i == $j ]] && { skip=1; echo -e "\033[32m Keeping $i \033[0m"; break; } | |
done | |
[[ -n $skip ]] || { echo -e "\033[31m Deleting $i \033[0m"; } | |
# [[ -n $skip ]] || { echo -e "\033[31m $(git branch -D $i) \033[0m"; } | |
done | |
} | |
clean $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment