ProbableOdyssey

Finding Git branches faster with FZF

One of my favourite CLI tools is FZF by junegunn. When you pipe a list of entries to it, it brings up a TUI that allows you to fuzzy match entries from that list

I only need to type a few characters to select an element from a large list!

One common problem I encounter is sorting through all of my branches on a git repository. Especially in repositories where your branches need to conform to a long template.

For example, checking out the repository Marimo, there’s many branches:

1git branch --all | wc -l
2# 162

So I’ve add this alias to my ~/.gitconfig:

[alias]
    co = "!git checkout $(git branch --format '%(refname:short)' | fzf)"

So when I execute git co, fzf allows me to select a branch with a fuzzy match, then the alias will check it out!

To install FZF, you can use Homebrew:

1brew install fzf

Check out their Readme for more details for configuration, adding shell shortcuts, the syntax for different types of searches.

Reply to this post by email ↪