Skip to content

Instantly share code, notes, and snippets.

@dteoh
Last active February 4, 2025 13:18
Show Gist options
  • Save dteoh/575c3a5a6025ac2591d2062243a4e2a3 to your computer and use it in GitHub Desktop.
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

kumar303 commented Aug 1, 2024

Amazing ✨ 💫 🙏

@Sorcy
Copy link

Sorcy commented Sep 5, 2024

For this you are a prince among men!

@mfedak-tqgg
Copy link

beautiful!

@bodinsamuel
Copy link

🫡

@BaochengHan-TomTom
Copy link

This saves lives!

@awoimbee
Copy link

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
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

Thanks for this, amazing! 🙏

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