Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
Last active February 19, 2025 14:48
Show Gist options
  • Select an option

  • Save emmanuelnk/818a810e5a65de1c77025df4c0ae88f2 to your computer and use it in GitHub Desktop.

Select an option

Save emmanuelnk/818a810e5a65de1c77025df4c0ae88f2 to your computer and use it in GitHub Desktop.
Interactive Menu for most recent git local branches (scroll and checkout)

An interactive version using fzf:

  • First install fzf
brew install fzf
  • Then add the alias to .gitconfig
recent = "!f() { branch=$(git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(refname:short)%09%(color:yellow)%(committerdate:relative)%09%(color:blue)%(subject)%09%(color:magenta)%(authorname)%(color:reset)' --color=always | column -ts$'\t' | fzf --ansi --delimiter=$'\t' --height=40% --reverse --prompt='Checkout> ' | cut -f1 | sed 's/^[* ]*//'); if [ -n \"$branch\" ]; then git checkout \"${branch%%[[:space:]]*}\"; fi; };

Now you can just run git recent, and scroll through recent refs using arrow keys, Enter to checkout the branch or Esc to exit the menu

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment