Created
July 4, 2019 16:45
-
-
Save jnaO/776f2638b2310843e6ba600a6b9a0ee4 to your computer and use it in GitHub Desktop.
git delete local 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
#!/bin/bash | |
# Author: | |
# jnaO | |
red=$(tput setaf 1) | |
yellow=$(tput setaf 3) | |
blue=$(tput setaf 4) | |
green=$(tput setaf 7) | |
normal=$(tput sgr0) | |
for branch in $(git for-each-ref --format='%(if)%(HEAD)%(then)*%(end)%(refname:short)' refs/heads/); do | |
if [[ $branch == 'master' || $branch == *"*"* ]] ; then | |
continue | |
fi | |
read -p "${yellow}Delete $branch?${normal} (${purple}Y${normal}/n) " DELETE_BRANCH | |
if [[ $DELETE_BRANCH != 'n' ]] ; then | |
printf "${red}" | |
git branch -D $branch | |
printf "${normal}" | |
else | |
printf "${blue}Kept branch $branch${normal}\n" | |
fi | |
done | |
printf "\n\n${yellow}Remaining branches:${normal}\n" | |
for branch in $(git for-each-ref --format='%(if)%(HEAD)%(then)*%(end)%(refname:short)' refs/heads/); do | |
if [[ $branch == *"*"* ]] ; then | |
printf "${blue}${branch}${normal}" | |
else | |
printf " ${branch}" | |
fi | |
printf "\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment