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

Sunny Golovine

May 17, 2021

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.

Other Posts

Check out some of my other recent posts.

Three Links - A Wikipedia Game

Jul 27 | general

So how much do I owe in taxes?

Nov 17, 2022 | general

Building a better guestbook for my site.

Oct 28, 2022 | tech

America Needs Better Zoning

Oct 2, 2022 | living

File Based Routing Needs to Stop (Being The Only Option)

Sep 22, 2022 | tech

Copyright 2023, Sunny Golovine

Views expressed in this post are strictly my own.

Version: 1.2.0 (5345ace)