Skip to content

Instantly share code, notes, and snippets.

@camsteffen
Last active April 6, 2020 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camsteffen/1920a4e53897b3336c176542383cd5e8 to your computer and use it in GitHub Desktop.
Save camsteffen/1920a4e53897b3336c176542383cd5e8 to your computer and use it in GitHub Desktop.
Deletes all merged branches with an option to edit the list
#!/usr/bin/env zsh
setopt EXTENDED_GLOB
# get list of all merged branches
branches=(${(f)"$(git branch --format '%(refname:short)' --merged)"})
# remove current branch
current=("$(git branch --show-current)")
branches=(${branches:|current})
# remove master|develop branches
branches=(${branches:#(master|dev*)})
if ((${#branches} == 0)) {
print 'No merged branches'
exit
}
print -- "${(F)branches}\n"
read '?Delete these merged branches? '
integer dodelete=0
case $REPLY in
'e')
# edit branches
branches=(${(f)$(vipe <<< ${(F)branches})})
if ((? == 0 && ${#branches} > 0)) {
dodelete=1
}
;;
'y')
dodelete=1
;;
esac
if ! ((dodelete)) {
print 'No branches deleted'
exit
}
git branch -d "$branches[@]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment