Developer Productivity

Git Worktrees: Parallel Branches Without the Chaos

Stashing mid-refactor to review a colleague's PR is a tax you pay every day. Worktrees eliminate it by letting multiple branches exist on disk at once.

M. Calder7 min read

Every developer knows the rhythm: you are twenty minutes into a refactor, a colleague pings you to review a pull request, and you face the choice — commit half-finished work, stash it and pray the stash applies cleanly, or make them wait. Git worktrees remove the choice entirely.

What a worktree actually is

A worktree is a second working directory that shares the same repository. Same commits, same branches, same history — different files on disk. You can have one checkout on main for review and another on feature/auth for your refactor, both open in your editor, with no stashing.

Shell
# From your main repo
git worktree add ../project-review main

Now ../project-review is a full working directory on main. cd into it, run your review there, and your original checkout is untouched.

The layout that works

A common setup is to dedicate a parent directory to worktrees:

Code
~/code/
  project/          # your main checkout
  project-review/   # worktree on main, for PRs
  project-exp/      # worktree for experiments

Each worktree can be opened in a separate editor window. Because they share the .git directory, fetching in one is visible in all of them — no duplicate clones, no wasted disk.

The two commands you will actually use

Shell
git worktree add <path> <branch>   # create
git worktree remove <path>         # clean up
git worktree list                  # see what exists

That is most of it. The feature is older than people think and surprisingly uncontroversial.

Pitfalls to know

  • Branches are exclusive. A branch checked out in one worktree cannot be checked out in another. This is a feature — it prevents the conflicts worktrees exist to avoid.
  • Tooling that assumes one working directory (some linters, some IDEs configured globally) may need per-worktree configuration.
  • Node modules and build artifacts are per-worktree. A fresh worktree needs its own install. Use this to your advantage: a clean worktree is a clean build.

When worktrees pay off most

  • Reviewing PRs while keeping your in-progress work intact.
  • Running long tasks (test suites, benchmarks) in one tree while coding in another.
  • Comparing two branches side by side without git diff gymnastics.

Takeaways

  • A worktree is a second working directory sharing one repository.
  • One branch per worktree; that exclusivity is the point.
  • Fresh worktrees mean fresh installs — embrace it for clean builds.

Worktrees are not a power-user trick. They are a quiet, durable improvement to daily workflow that most teams never adopt simply because the stash reflex is so ingrained.

Related briefs