Created
June 7, 2018 02:54
-
-
Save libook/610b9b53bc5b4b972644edd56e624bbc to your computer and use it in GitHub Desktop.
Remove abandoned branch
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/zsh | |
# Warning! This script will remove all local branches that not tracking remote branches. | |
git fetch --prune | |
echo "*******" | |
echo "Branches to remove:\n" | |
# TODO Reuse code and unify solution. | |
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | |
git branch -vv | grep -v '\[origin/' | awk '{print $1}' | |
echo "\nThis will remove all branches that doesn't exist on remote!" | |
while true; do | |
read "yn?Continue anyway? Input 'Yes' to do this. " | |
case $yn in | |
Yes* ) | |
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d | |
git branch -vv | grep -v '\[origin/' | awk '{print $1}' | xargs git branch -d | |
break | |
;; | |
* ) | |
echo "Not 'Yes'. Canceled." | |
exit | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment