Skip to content

Instantly share code, notes, and snippets.

@aaronshaf
Created November 30, 2023 02:42
Show Gist options
  • Save aaronshaf/ae3833f679b5488e5ffaff15ceef57d9 to your computer and use it in GitHub Desktop.
Save aaronshaf/ae3833f679b5488e5ffaff15ceef57d9 to your computer and use it in GitHub Desktop.
shell utils for listing and deleting git branches
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