Skip to content

Instantly share code, notes, and snippets.

@apottere
Last active September 16, 2020 20:31
Show Gist options
  • Save apottere/6378eca9213a7e03a5ee29c458c002ba to your computer and use it in GitHub Desktop.
Save apottere/6378eca9213a7e03a5ee29c458c002ba to your computer and use it in GitHub Desktop.
#!/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