Skip to content

Instantly share code, notes, and snippets.

@dteoh
Last active March 9, 2026 14:21
Show Gist options
  • Select an option

  • Save dteoh/575c3a5a6025ac2591d2062243a4e2a3 to your computer and use it in GitHub Desktop.

Select an option

Save dteoh/575c3a5a6025ac2591d2062243a4e2a3 to your computer and use it in GitHub Desktop.
Interactively delete git branches locally

Delete multiple Git branches with a UI

This assumes you have installed fzf.

$ git branch --no-color | fzf -m | xargs -I {} git branch -D '{}'

Press tab to mark a branch, shift-tab to unmark. Press enter and all marked branches will be deleted.

Add custom subcommand

You can add custom subcommands to git. Here's how I added the above script as git boom.

  1. Create a file named git-boom. This file should be located inside of a directory in $PATH (either make a new directory and add it to $PATH, or use an existing location).
  2. Add the script contents. Example from my git-boom file.
  3. Make the file executable. chmod +x ./git-boom
  4. Now you can run git boom
@kumar303
Copy link
Copy Markdown

kumar303 commented Aug 1, 2024

Amazing ✨ 💫 🙏

@Sorcy
Copy link
Copy Markdown

Sorcy commented Sep 5, 2024

For this you are a prince among men!

@mfedak-tqgg
Copy link
Copy Markdown

beautiful!

@bodinsamuel
Copy link
Copy Markdown

🫡

@BaochengHan-TomTom
Copy link
Copy Markdown

This saves lives!

@awoimbee
Copy link
Copy Markdown

Will you marry me ?

function git {
  if [[ "${1:-}" == "branch" && "${2:-}" == "-i" ]]; then
    git branch --no-color | fzf -m | xargs -I {} git branch -D '{}'
  else
    command git $@
  fi
}

@dteoh
Copy link
Copy Markdown
Author

dteoh commented Dec 11, 2024

I'm not sure what's suddenly generating traffic to this gist, but happy to see other people are finding this useful :)

I updated the gist to include instructions for adding this as a custom git subcommand.

@MarkusPettersson98
Copy link
Copy Markdown

Thanks for this, amazing! 🙏

@MarkoZabcic
Copy link
Copy Markdown

Very nice, thanks!

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