Last active
July 2, 2026 16:42
-
-
Save seanbecker15/5796bf8960927a703f920ed70be64733 to your computer and use it in GitHub Desktop.
ghist - list recent branches and commits
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
| #!/usr/bin/env bash | |
| # ghist — pick from the 5 most recently active local branches and check it out. | |
| # | |
| # "Recent" = most recent commit date. Pass a number to change how many | |
| # branches are shown, e.g. `ghist 10`. | |
| # | |
| # Uses fzf: arrows or type-to-filter to pick, Enter to select, Esc to cancel. | |
| set -euo pipefail | |
| count="${1:-5}" | |
| if ! git rev-parse --git-dir >/dev/null 2>&1; then | |
| echo "ghist: not inside a git repository" >&2 | |
| exit 1 | |
| fi | |
| if ! command -v fzf >/dev/null 2>&1; then | |
| echo "ghist: fzf not found — install it with 'brew install fzf'" >&2 | |
| exit 1 | |
| fi | |
| branch="$( | |
| git for-each-ref --sort=-committerdate --count="$count" \ | |
| --format='%(refname:short)' refs/heads | | |
| fzf --height="$((count + 4))" --reverse --no-info \ | |
| --prompt='branch> ' \ | |
| --preview 'git log --oneline --color=always -5 {}' \ | |
| --preview-window=right:60% | |
| )" || exit 0 | |
| git checkout "$branch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment