Last active
September 16, 2020 20:31
-
-
Save apottere/6378eca9213a7e03a5ee29c458c002ba to your computer and use it in GitHub Desktop.
https://gist.github.com/d3d-z7n/1af74ae78e0b8c4828a6c5c760ff665a, but for the inferior shell
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/bash | |
set -euo pipefail | |
reset=$'\033[0;0m' | |
cyan=$'\033[0;36m' | |
bred=$'\033[1;31m' | |
# Remove no longer existing remote branches. | |
git fetch --prune | |
# Find all branches with a deleted remote branch. | |
IFS=$'\n' | |
branches=($(git branch -vv | grep ": gone]" | awk '{ print $1 }')) | |
if [[ $#branches == 0 ]]; then | |
echo "No pruneable local branches found." | |
exit 0 | |
fi | |
echo -e "${cyan}The following local branches will be deleted:${reset}" | |
for branch in "${branches[@]}"; do | |
echo -e "${bred}$branch${reset}" | |
done | |
echo | |
read -p "${cyan}Continue? (y/n)${reset} " 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