Git Worktree

No Change
trial
First Added:May 28, 2026

Git Worktree

Git worktrees let one git repository hold several checked-out branches at once, each in its own directory. We trial the technique when parallel work beats stashing or re-cloning: feature branch plus PR review, hotfix while main stays clean, or agent tooling that needs an isolated checkout per branch.

Blurb

Manage multiple working trees attached to the same repository. A git repository can support multiple working trees, allowing you to check out more than one branch at a time.

Summary

What it is: A repo has one main worktree (from git clone or git init) and zero or more linked worktrees. Each worktree shares the same object database but has its own HEAD, index, and files on disk. Git tracks metadata under .git/worktrees/.

When to use:

SituationWhy worktrees help
Feature + reviewKeep main checked out while you review a Pull Request in another folder
Hotfix interruptBranch off production without disturbing in-progress edits
Parallel agentsTools like Cursor best-of-N runners can use one worktree per attempt
Long buildsRun tests in one tree while you edit in another

When to skip: Single-branch solo work with no context switching. Repos where disk space is tight (each tree duplicates the working copy). Teams that prefer one clone per branch in CI only.

Core commands:

CommandPurpose
git worktree add ../path branchNew linked tree at ../path on branch
git worktree add -b new-branch ../pathCreate branch and check it out
git worktree listShow all trees, paths, and checked-out refs
git worktree remove ../pathDrop a linked tree (branch stays)
git worktree pruneClean stale admin files after manual deletes

Rules of thumb: One branch per worktree at a time (Git blocks duplicate checkouts). Run add from the main repo; put sibling paths outside the main tree (../feature-x) to avoid nested folders. Remove linked trees when done so .git/worktrees stays tidy.

Personal Experience

The reason this is a trial vs adopt is because it works different than normal git clone. IDEs can get confused, and they don’t always play nice with devcontainers, so your mileage may vary.

Our main usage is when we have to work on multiple branches at the same time (for example: main, staging, prod). In this case we structure things in a very specific way:

  1. Create a directory to contain the worktrees
    1. mkdir <repo name>
    2. cd <repo name>
  2. Clone the main worktree
    1. git clone <repo url> main
  3. Create all other worktrees as siblings
    1. cd main
    2. git worktree add ../staging staging
    3. git worktree add ../prod prod
  4. Use the correct directory / worktree for your work

Details

Versus alternatives:

ApproachTrade-off
git stashFast, but only one checkout; easy to lose context in a deep stash stack
Second git cloneFully isolated, but doubles fetch/storage and drift between clones
WorktreeShared objects, one remote config; must respect one-branch-per-tree rule

Detached HEAD trees: git worktree add --detach ../experiment gives a throwaway checkout for spikes or reproducing a bug at a specific commit without creating a branch.

Lock and move: git worktree lock prevents accidental removal (useful on shared machines). git worktree move relocates a tree if you reorganize directories.

Cleanup: If you delete a worktree folder by hand, run git worktree prune. Use git worktree repair after path moves or corrupted admin metadata.

Garden stance: Trial on any repo where you already adopt git and regularly switch branches mid-task. Promote to adopt once worktrees are part of your default local workflow.

References