Skip to content

Instantly share code, notes, and snippets.

@samkcarlile
Created September 6, 2025 16:23
Show Gist options
  • Select an option

  • Save samkcarlile/f8f1d24339dd8631cf21eba741df0b83 to your computer and use it in GitHub Desktop.

Select an option

Save samkcarlile/f8f1d24339dd8631cf21eba741df0b83 to your computer and use it in GitHub Desktop.
useful git zsh functions
unalias gbl
function gbl() {
# todo: colorize branches by last commit
# todo: show 10 by default
gb --sort=committerdate |
tail -n 5 |
gum filter --limit=1 --header="Type to checkout a branch" --placeholder="" |
xargs -I _ git checkout _ || echo Current branch already checked out.
}
function gcz() {
# Get local branches only (filter out remote branches)
local branches=$(git branch --format='%(refname:short)' | grep -v '^origin/')
if [[ -z "$branches" ]]; then
echo "No local branches"
return 1
fi
local branch
if [[ $# -eq 1 ]]; then
# Auto-checkout first fuzzy match
branch=$(echo "$branches" | fzf --filter="$1" | head -n1)
if [[ -z "$branch" ]]; then
echo "No branch matches '$1'"
return 1
fi
else
# Interactive mode with fzf
branch=$(echo "$branches" | fzf --prompt="Checkout branch: ")
if [[ -z "$branch" ]]; then
echo "No branch selected"
return 1
fi
fi
# Checkout the selected branch
git checkout "$branch"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment