Skip to content

Instantly share code, notes, and snippets.

@kbfreder
Last active May 16, 2022 21:29
Show Gist options
  • Save kbfreder/9056ccb2465c0b828e11800ed00130de to your computer and use it in GitHub Desktop.
Save kbfreder/9056ccb2465c0b828e11800ed00130de to your computer and use it in GitHub Desktop.
# this is intended to live as a function inside ~/.bash_profile
function git_del_branches {
pattern=$1
im=$2
usage="git_del_branches -p pattern [-i]
Match and delete git branches that match <pattern>.
Use the -i (--inverse) flag to delete branches that do
not match <pattern>"
if [ "$pattern" = "-h" ]; then
echo "$usage"
else
if [ "$im" = "" ]; then
invert=false
else
invert=true
fi
if $invert; then
git branch | grep -v "$pattern" | xargs git branch -D
else
git branch | grep "$pattern" | xargs git branch -D
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment