Created
September 6, 2025 16:23
-
-
Save samkcarlile/f8f1d24339dd8631cf21eba741df0b83 to your computer and use it in GitHub Desktop.
useful git zsh functions
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
| 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