Created
September 22, 2017 20:38
-
-
Save getfatday/27aa19f9acff1fe963f1840b78bb23f4 to your computer and use it in GitHub Desktop.
Remove unused 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
#!/usr/bin/env bash | |
usage() | |
{ | |
echo "usage: git unused [-D]" | |
} | |
while getopts "hD" opt; do | |
case $opt in | |
h) | |
usage | |
exit 1 | |
;; | |
D) | |
DELETE="1" | |
;; | |
\?) | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | while read branch; do | |
if [ ! -z "$DELETE" ]; then | |
git branch -D $branch | |
else | |
echo Would remove $branch | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment