Created
January 31, 2018 23:00
-
-
Save ross-urban/81ffe3bc783801572445632a49a4bdad to your computer and use it in GitHub Desktop.
Delete local git branches with deleted remotes
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
function orphaned-branches { | |
git branch -vv | cut -c 3- | awk '$4 ~/gone\]/ { print $1 }' | |
} | |
function gitclean { | |
git remote -v prune origin | |
echo "WARNING: The following branches will be deleted!" | |
RESPONSE=$(orphaned-branches) | |
echo "$RESPONSE" | |
echo | |
echo "Are you sure (yN)?" | |
read yn | |
if [[ $yn =~ ^[yY]$ ]] | |
then | |
echo "$RESPONSE" | xargs git branch -D | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment