| 1 | ## switch branch with preview |
| 2 | # |
| 3 | function gb |
| 4 | command git rev-parse --git-dir >/dev/null ^/dev/null; or begin; echo "not a git repo"; return 1; end |
| 5 | set -l branch (git for-each-ref --format='%(refname:short)' refs/heads refs/remotes \ |
| 6 | | sort -u | fzf --prompt="git branch> " --height=70% \ |
| 7 | --preview 'git log --oneline --decorate -n 20 {1}') |
| 8 | test -n "$branch"; or return |
| 9 | set branch (string replace -r '^remotes/[^/]+/' '' -- $branch) |
| 10 | git checkout $branch |
| 11 | end |