Skip to content

Instantly share code, notes, and snippets.

@selfish
Created June 3, 2025 16:39
Show Gist options
  • Select an option

  • Save selfish/9484c19cb85f18604bc91ea5846646d9 to your computer and use it in GitHub Desktop.

Select an option

Save selfish/9484c19cb85f18604bc91ea5846646d9 to your computer and use it in GitHub Desktop.
Fuzzy Checkout from Recent Branches in Git
ccr() {
local limit branch
# shellcheck disable=SC2031
limit="${1:-15}"
branch="$(git reflog | awk '/checkout:/ {print $NF}' | awk '!seen[$0]++' | head -n "${limit}" | fzf --prompt "Select a recent branch: ")"
[ -n "${branch}" ] && git switch "${branch}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment