Skip to content

Instantly share code, notes, and snippets.

@jmatsu
Created April 16, 2021 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmatsu/a8cffbafaebc0c998e0c222e99138258 to your computer and use it in GitHub Desktop.
Save jmatsu/a8cffbafaebc0c998e0c222e99138258 to your computer and use it in GitHub Desktop.
# Register a filter command for Git commands
git config --system --add mine.filter fzf
# Show checked-out branches in reflog (distinct, and not sorted by the checked-out time)
git config --system --add alias.head-history "\!f() { git reflog HEAD | grep 'checkout:' | awk '\$0=\$NF' | sort | uniq; }; f"
# Select and switch HEAD to the branch
git config --system --add alias.switch-to "\!f() { local -r ref=\"\$(git head-history | \$(git config --get mine.filter))\"; [[ -n \"\$ref\" ]] && git switch \"\$ref\"; }; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment