-
-
Save wojtha/40a8223a3304d5c7a981d3afc1936cfe to your computer and use it in GitHub Desktop.
Remove local git branch when it is linked to non-existing remote branch
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 | |
# Based on https://stackoverflow.com/a/33548037 | |
# Maybe we can add this: https://stackoverflow.com/a/32166469 | |
echo "*** Local tracking branches with removed remote branches:" | |
# List files | |
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | |
# Ask user | |
read -p "*** Remove those branches? (y/N) " -r -s -n 1 | |
# Set default answer | |
[ -z "$REPLY" ] && REPLY="n" | |
# Delete or not | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
echo ">> Yes" | |
echo "*** Removing following local branches:" | |
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -n 1 git branch -D | |
echo "*** DONE!" | |
else | |
echo ">> No" | |
echo "*** Nothing to do" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment