Last active
April 1, 2019 22:33
-
-
Save tmcgee123/feef4a7641ee1d9bc15f to your computer and use it in GitHub Desktop.
Clears the branches in current working directory that are not master, develop, or current checkout'd out branch
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 | |
#go to the current working directory | |
pwd | | |
while CWD= read -r line; do | |
cd "$line" | |
done | |
#designate local branches to skip | |
SKIPPEDBRANCHES="master develop" | |
#current branch regex, starts with * | |
CURRENTREGEX="^\*." | |
#grep local branches list to separate by space | |
git branch | | |
while IFS= read -r line; do | |
CURRENTBRANCH="${line// /}" | |
SKIPBRANCH="false" | |
for skippedbranch in $SKIPPEDBRANCHES ; do | |
#validate current branch name against skipped and not the current branch | |
if [[ $CURRENTBRANCH == $skippedbranch ]] || [[ $CURRENTBRANCH =~ $CURRENTREGEX ]]; then | |
SKIPBRANCH="true" | |
fi | |
done | |
#delete branch if passed checks | |
if [[ "$SKIPBRANCH" == "false" ]]; then | |
git branch -D "$CURRENTBRANCH" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment