Last active
March 28, 2017 12:37
-
-
Save baz8080/b75a56af16740e412255d80ba79980be to your computer and use it in GitHub Desktop.
clearGit.sh
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 | |
GIT_STATUS=`git status --porcelain` | |
if [ ! -z "$GIT_STATUS" ] ; then | |
echo "This script will not run if git status --porcelain indicates that changes are present" | |
exit 1 | |
fi | |
set -e | |
git checkout master | |
echo "Going to loop through merged branches" | |
for branch in `git branch --merged | grep -v "\*" | xargs -n 1`; do | |
echo "Delete '$branch' ? [y|n]" | |
read choice | |
if [[ "$choice" == "y" ]]; then | |
git branch -D "$branch" | |
fi | |
done | |
set +e | |
echo "Going to loop through potentially unmerged branches" | |
for branch in `git branch | grep -v "\*" | xargs -n 1`; do | |
echo "Delete '$branch' ? [y|n]" | |
read choice | |
if [[ "$choice" == "y" ]]; then | |
git branch -D "$branch" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment