Skip to content

Instantly share code, notes, and snippets.

@baz8080
Last active March 28, 2017 12:37
Show Gist options
  • Save baz8080/b75a56af16740e412255d80ba79980be to your computer and use it in GitHub Desktop.
Save baz8080/b75a56af16740e412255d80ba79980be to your computer and use it in GitHub Desktop.
clearGit.sh
#!/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