-
-
Save przemyslawjanpietrzak/9086d22c2e5d045290184e79c4f31b74 to your computer and use it in GitHub Desktop.
git_clean_local_branches
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
#!/bin/bash | |
function git_clean_local_branches { | |
TO_REMOVE=`git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}'`; | |
TO_REMOVE_LINES=`git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | wc -l` | |
if [ "$TO_REMOVE_LINES" -ne 0 ]; then | |
echo "Removing branches..." | |
printf "\n$TO_REMOVE\n\n"; | |
echo "Proceed?"; | |
select result in Yes No; do | |
if [[ "$result" == "Yes" ]]; then | |
echo "Removing in progress..." | |
echo "$TO_REMOVE" | xargs git branch -d; | |
if [ $? -ne 0 ]; then | |
echo "Some branches was not removed, you have to do it manually!" | |
else | |
echo "All branches removed!" | |
fi | |
fi | |
break; | |
done; | |
else | |
echo "You have nothing to clean" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment