Last active
August 8, 2023 16:49
-
-
Save bgreenlee/70f9edd83b30734673a5c9c2b07fe9b0 to your computer and use it in GitHub Desktop.
Interactive git branch deletion with fzf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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