Skip to content

Instantly share code, notes, and snippets.

@tommeier
Created June 21, 2010 04:51
Show Gist options
  • Save tommeier/446412 to your computer and use it in GitHub Desktop.
Save tommeier/446412 to your computer and use it in GitHub Desktop.
#add this to your ~/.bash_profile and reload teminal
function delete_all_local_branches {
printf "\n\n\n\n== Would you like to delete ALL local branches? \nTHIS ACTION CANNOT BE UNDONE WITHOUT A WIZARDS HAT\nPlease select option (or any key to skip):\n"
echo "1) Delete all - (git branch branch_name -D)"
echo "-) Skip"
read -n1 -s -r -t30 INPUT
case "$INPUT" in
"1")
echo "== Deleting ALL local branches (please wait)..."
git for-each-ref --shell --format="%(refname)" refs/heads | \
while read branch
do
branch_name=${branch/refs\/heads\//}
if [ $branch_name != "'master'" -a $branch_name != "'dev'" ]; then
git branch ${branch_name//\'/} -D
echo "${branch_name} deleted."
else
echo "--> ${branch_name//\'/} skipped..."
fi
done;;
*)
echo "== Delete skipped." ;;
esac
}
@tommeier
Copy link
Author

Also... Delete all local tags on your system (then just run git fetch --tags to get them all again new, useful when the git repo is cleaned out)

function delete_all_local_tags {
git-for-each-ref --shell --format="%(refname)" refs/tags |
while read tag
do
tag_name=${tag/refs/tags//}
git tag ${tag_name//'/} -d
done
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment