Created
January 4, 2017 19:57
-
-
Save wdawson/39a3d018add4b188efb48e12bd7a76db to your computer and use it in GitHub Desktop.
Bash script to remove git branches and remote tracking branches (named the same thing in your origin remote)
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
#!/bin/bash | |
RED='\033[1;31m' | |
YELLOW='\033[1;33m' | |
WHITE='\033[1;37m' | |
GREEN='\033[1;32m' | |
NO_COLOR='\033[0m' | |
if [ ! -d ".git" ] || !(git rev-parse --git-dir > /dev/null 2>&1); then | |
echo -e "${YELLOW}No git repository found here${NO_COLOR}" | |
exit 1 | |
fi | |
BRANCHES=$(git for-each-ref --format '%(refname)' refs/heads/ | cut -d/ -f3) | |
for CURRENT_BRANCH in $BRANCHES; do | |
if [ "$CURRENT_BRANCH" = "master" ]; then | |
echo -e "Skipping master branch..." | |
continue | |
fi | |
echo -e "Do you want to remove ${WHITE}$CURRENT_BRANCH${NO_COLOR} ?[Y/n/exit]" | |
read CHOICE | |
case $CHOICE in | |
y|Y|'') | |
echo -e "${RED}Deleting branch...${NO_COLOR}" | |
git push origin :$CURRENT_BRANCH | |
git branch -D $CURRENT_BRANCH | |
;; | |
n|N) | |
echo -e "Skipping..." | |
;; | |
'exit') | |
break | |
;; | |
*) | |
echo -e "${YELLOW}Invalid Input.${NO_COLOR} Skipping..." | |
echo -e "Usage: 'y'(default), 'n', or 'exit'" | |
;; | |
esac | |
done | |
echo -e "${GREEN}Done${NO_COLOR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment