Hima Blog LogoHima's Blog

Git Worktree: Parallel Development Made Easy

5 min read

by Hima

gitdevelopmenttechproductivityworktree

The Stash Dance We All Know

This happens to me often, I'm in the focus zone, working on a complex feature or something in a one track manner. My code is in that weird messy-but-progressing state where everything makes sense in your head at that point in time but would look absolutely like slop anyone else other than myself. Then a message comes in: "Can you review this PR real quick?" or some urgent tasks comes in and I'll have to context switch.

What follows is a ritual every developer knows too well:

git stash
git checkout main
git pull
git checkout pr-branch
# Review, test, provide feedback
git checkout feature-branch
git stash pop
# Wait, where was I again?

The mental context you had is completely gone. The flow state you were in is also gone, you most likely can't find back that mental state that you were in. And worst of all, if you're unlucky, you might even face stash conflicts or accidentally pop the wrong stash from a week ago.

There has to be a better way, right? And there is.

Introducing Git Worktree

Basically, Git Worktree allows you to have multiple working directories attached to a single repository without having to clone them individually and checkout to a new branch every time. Each worktree can have a different branch checked out, and the best part is, they all share the same Git history!

So now, instead of stashing your current work and switching branches within a single directory, you simply switch directories. Your feature branch stays exactly as you left it - files open, changes in progress, terminal running. You just cd into another folder to work on something else, and run a Claude Code session on that particular folder.

The Bare Repository Pattern

The cleanest way to use worktrees is with a bare repository setup, it is easy to visualize and understand. Instead of having a typical .git folder inside your project, you structure it like this:

my-project/
├── .bare/              # The actual git repository (bare clone)
├── main/               # Worktree for main branch
├── feature-auth/       # Worktree for auth feature
├── feature-dashboard/  # Worktree for dashboard feature
└── hotfix-login/       # Worktree for urgent fix

Each folder is a complete working directory with its own branch checked out. Want to review a PR? Just open the relevant worktree folder. Need to test something on main while your feature builds? Both are available simultaneously.

The .bare directory holds all the Git data - commits, branches, history - while each worktree folder contains only the working files for its specific branch.

Why This Changes Everything

No More Stashing

The most immediate benefit is obvious: you never need to stash again for context switching. Your work stays exactly where you left it.

Parallel Development

Running a slow test suite on your feature branch? Waiting for CI to run for a particular branch? Open another worktree and keep coding. Building the project for production while developing? No problem. Each worktree is completely independent and you will not be blocked at all.

Clean PR Reviews

When reviewing pull requests, you can have the PR branch in its own worktree. Test it, run it, break it - all without touching your current work. When you're done, the worktree is right there for next time.

Multiple IDEs and Frictionless Context Switching

You can have your JetBrains open on your feature branch in one worktree and another instance open on a hotfix in a different worktree. Completely separate contexts, no mental overhead of remembering which branch you're on.

Claude Code + Git Worktree = Multiplied Productivity

This is where things get interesting. If you're using Claude Code for development, the traditional workflow looks something like:

  1. Prompt Claude with a task
  2. Wait for implementation and doomscroll on Reddit
  3. Test and verify
  4. Prompt for fixes or next task
  5. Repeat

It's sequential by nature, you're blocked while waiting for each response.

With worktrees, you can run multiple Claude Code sessions simultaneously:

my-project/
├── .bare/
├── main/               # Claude Code session: fixing bugs
├── feature-auth/       # Claude Code session: implementing login
└── feature-api/        # Claude Code session: building endpoints

In this way, I can run three Claude Code instances and not have to wait and doomscroll while Claude works on authentication. Now, I can have a worktree where another session handles API endpoints in a different worktree, and a third addresses bug fixes on main. Each session has its own isolated context without conflict.

Instead of prompt-wait-test-repeat on a single feature, I'm now running three development streams in parallel. The productivity multiplication is real.

Quick Start

Here are the essential commands to get started:

# Add a new worktree for a branch
git worktree add ../feature-name feature-branch

# List all worktrees
git worktree list

# Remove a worktree when done
git worktree remove ../feature-name

For the bare repository pattern, you'd clone with --bare and set up worktrees from there. There are plenty of detailed guides online for the initial setup.

The Shift in Workflow

Git Worktree fundamentally changes how we think about branch management. Branches stop a dramatic context switch friction where it's you switch between and become places you work in. The cognitive overhead of context switching drops dramatically and for people who are more context focused on one thing, this helps a lot.

Combined with AI-assisted development tools such as Claude Code, this pattern unlocks genuine parallel development. You're no longer limited to one task at a time, waiting for builds or AI responses. Now, multiple workstreams can progress simultaneously, each in its own clean environment, you can even build your orchestrator of Claude to link all worktrees together!

If you've ever felt frustrated by the stash-switch-pop dance and weaving or wished you could work on multiple things at once, give Git Worktree a try!