Skip to content

Instantly share code, notes, and snippets.

@bgreenlee
Last active August 8, 2023 16:49
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 bgreenlee/70f9edd83b30734673a5c9c2b07fe9b0 to your computer and use it in GitHub Desktop.
Save bgreenlee/70f9edd83b30734673a5c9c2b07fe9b0 to your computer and use it in GitHub Desktop.
Interactive git branch deletion with fzf
# gbd - interactive git branch deletion
# based off https://www.peterp.me/articles/cli-tips-interactive-branch-delete/
# use tab to select multiple
# Drop this in your .bashrc or .zshrc (assumes fzf is installed)
gbd() {
local branches branch
branches=$(git for-each-ref --sort=-committerdate refs/heads/ --format="[%(committerdate:short)] %(color:bold green)%(refname:short)%(color:reset) - %(contents:subject)" --color=always | egrep -v main) &&
branch=$(echo "$branches" | fzf --multi --ansi --preview 'git show {2}' ) &&
git branch -D $(echo "$branch" | awk '{print $2}')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment