Last active
September 16, 2020 19:54
-
-
Save d3d-z7n/1af74ae78e0b8c4828a6c5c760ff665a to your computer and use it in GitHub Desktop.
Prompt for and delete local branches that are tracking deleted remote branches
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
#!/usr/bin/env zsh | |
# Remove no longer existing remote branches. | |
git fetch --prune &> /dev/null | |
# Find all branches with a deleted remote branch. | |
branches=(${(@f)$(git branch -vv | grep ": gone]" | awk '{ print $1 }')}) | |
if [[ $#branches == 0 ]]; then | |
print -P "No pruneable local branches found." | |
exit 0 | |
fi | |
print -P "%F{cyan}The following local branches will be deleted:\n%B%F{red}" | |
print -f "%s\n" ${branches[@]} | |
print -nP "%b%F{cyan}\nContinue (y/n)?%f " | |
read -q "confirmation?" | |
if [[ $confirmation == "y" ]]; then | |
echo | |
git branch -D ${branches[@]} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment