Pencils, Not Stencils: A Better Way to Prune Git Branches: fzf and a Tiny Loop

At Atomic, we build all kinds of software, from deep systems integrations to greenfield apps. But sometimes, it’s the tiniest tools that deliver surprisingly big wins.

Here’s a shell script I wrote to solve a problem that every dev hits eventually: cleaning up old Git branches. Yeah, you can prune Git branches manually, or with one-liners, or via your IDE. However, I had a bunch of branches to delete, and there were just enough of them that manual deletion felt annoying. And they had just enough variation that full lights-out automation was probably going to be more work than it was worth. So I split the difference and built a human-in-the-loop automation:


#!/usr/bin/env zsh

while true; do
  branches=$(git branch --format "%(refname:short)")
  choice=$(echo $branches |
            (echo "Done"; cat -) |
            fzf --header="Select a branch to delete. Select Done to exit." \
                --layout=reverse \
                --height=20 \
                --border \
                --ansi)
  if [[ "$choice" == "Done" ]]; then
    exit 0
  elif [[ -n "$choice" ]]; then
    git branch -d "$choice"
  fi
done

Why It Works

The neat part is the injection of a “Done” option into the fzf menu on each iteration. Doing that lets me pick from a list of branches while minimizing the time I spend moving data around for the computer. Now I just

  • Look at a list of branch names
  • Type a few characters to filter
  • Pick one that is definitely safe to delete
  • Tap return to move on
  • Bail out when I’m done

Toolsmithing for Real Work

This script took a few minutes to write, and then paid for itself immediately. Because I saved it as a named script, I can use it for branch cleanup in the future. Because I took a few minutes to design it with minimal dependencies, I can share it with my team easily. Because it does one thing well, it’s easy to see how someone else might riff on that script to make a little loop that helps them do something other than delete branches.

🧠 Software should help people move faster, not force them into rigid patterns. Tools should be pencils, not stencils.

When we build internal tools or client-facing features at Atomic, this is a mindset that drives us. We look for the little accelerants that unlock flow, reduce friction, and free people up to focus on what matters.

Sometimes that’s a better dev tool. Sometimes it’s a just-right admin UI. Sometimes it’s a backend system that quietly solves the hard problems so humans don’t have to. And increasingly, we’re seeing how emerging tools are speeding up this kind of targeted micro-innovation. We’re going from insight to solution faster than ever. I’ll write more about that soon.

Pragmatic Innovation, Delivered

We bring that toolsmithing approach to every project. Sometimes the best solution is a complex architecture, and sometimes, the best solution is 15 lines of Bash that help your team get back to work.

If that’s your vibe, let’s talk. We love working with teams who value sharp tools and fast results.

Conversation

Join the conversation

Your email address will not be published. Required fields are marked *