Skip to content

Instantly share code, notes, and snippets.

@nolandc
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save nolandc/f070fe8eef1911e56a8d to your computer and use it in GitHub Desktop.

Select an option

Save nolandc/f070fe8eef1911e56a8d to your computer and use it in GitHub Desktop.
Interactive Git Branch Deletion
echo "Git Branch Deleletion (Interactive)"
# Grep out the current branch and branches too important to delete
list=$(git branch --list | grep -v \* | grep -v develop | grep -v master)
if [[ $list == '' ]]; then
echo "There are no branches to delete."
exit 0
fi
while read -r line; do
printf "Delete the branch '$line' ? [y/N]:"
read toDelete </dev/tty
if [[ $toDelete == 'y' ]]; then
git branch -D $line
else
echo "Not deleting $line"
fi
echo
done <<< "$list"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment