Created
November 30, 2023 02:42
-
-
Save aaronshaf/ae3833f679b5488e5ffaff15ceef57d9 to your computer and use it in GitHub Desktop.
shell utils for listing and deleting git branches
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
function b() { | |
local branches branch | |
branches=$(git for-each-ref --sort=-committerdate refs/heads/ --format="%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:blue)%(contents:subject)%(color:reset) %(color:green)(%(committerdate:relative))%(color:reset) [%(color:red)%(authorname)%(color:reset)]") \ | |
&& branch=$(echo "$branches" | fzf --ansi --no-sort) \ | |
&& branch=$(echo "$branch" | awk '{print $1}' | sed 's/\* //') \ | |
&& git checkout "$branch" | |
} | |
function db() { | |
local branches branch | |
branches=$(git for-each-ref --sort=-committerdate refs/heads/ --format="%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:blue)%(contents:subject)%(color:reset) %(color:green)(%(committerdate:relative))%(color:reset) [%(color:red)%(authorname)%(color:reset)]") \ | |
&& branch=$(echo "$branches" | fzf --ansi --no-sort) \ | |
&& branch=$(echo "$branch" | awk '{print $1}' | sed 's/\* //') \ | |
&& [[ "$branch" != "master" ]] && git branch -D "$branch" || echo "Cannot delete master branch" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment