Fuzzy Git Branch Checkout

If you use JIRA at work then your git branches likely look like PROJ-12345-description. Here's a little script you can use to checkout these branches quicker

Hey everyone, like many developers I use JIRA for issue tracking at work. One thing to know about JIRA is the git integration it offers but with one caveat, the branches all have to follow a common naming convention. After a few weeks of creating branches, running git branch in my local repository yields a list that looks something like this:


....and more

If you have 3-5 branches on your local machine it's not that big of a deal, but get 20+ and it starts taking some effort to find the branch you're looking for, especially if you work in an environment where features are very close together so branches end up looking like



The other day I got tired of looking through this massive list of branches and asked myself: "can we make checking out these branches better?". So like any programmer, I made a script on my lunch break to fuzzy search these branches

The Script



function path-search() {
  if [ -z "$1" ]; then
    echo "Branch not supplied"
    return 1

  branch=$(git branch | grep $1 | xargs)

  if [ -z "$branch" ]; then
    echo "No matching braches found"
    return 1

  git checkout $branch
  echo "Successfully checked out branch $branch"
  return 0

This script is far from perfect but it gets the job done. Feel free to add this to your dot files and edit as you see fit.

More Posts

Wouldn't it be nice to have your NetlifyCMS configuration in JS rather than YAML? Here's how you can do that.

Instead of rebuilding my website this year, I migrated it from Gatsby to NextJS. Here's how that went.

How to setup Storybook to work nicely with Styled Components custom theme.

There are tons of libraries out there that will help you with icons in React, but there's an even easier way.

A list of 10 awesome UI libraries that will help you bootstrap your next React project