Skip to content

Instantly share code, notes, and snippets.

@letsbreelhere
Created June 10, 2026 18:49
Show Gist options
  • Select an option

  • Save letsbreelhere/d08cde366136fefcdfa1f535cfe30e64 to your computer and use it in GitHub Desktop.

Select an option

Save letsbreelhere/d08cde366136fefcdfa1f535cfe30e64 to your computer and use it in GitHub Desktop.
Select git branches using fzf
# CTRL-B - Paste the selected git branch into the command line
fzf-git-branch-widget() {
setopt localoptions pipefail no_aliases 2>/dev/null
local branch
branch=$(
git branch --color=always --format="%(refname:short)%09%(color:yellow)%(committerdate:relative)%(color:reset)" --sort=-committerdate --all 2>/dev/null \
| grep -v HEAD \
| egrep -v '^origin' \
| sed 's/^[* ]*//' \
| sed 's#^remotes/[^/]*/##' \
| fzf --ansi --no-sort --reverse --height=40% --min-height=20 \
--delimiter=$'\t' --with-nth=1,2 --nth=1 \
| cut -f1
)
if [[ -n "$branch" ]]; then
LBUFFER="${LBUFFER}${branch}"
fi
zle reset-prompt
}
zle -N fzf-git-branch-widget
bindkey -M emacs '^B' fzf-git-branch-widget
bindkey -M vicmd '^B' fzf-git-branch-widget
bindkey -M viins '^B' fzf-git-branch-widget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment