What is a git worktree, and why it suddenly matters

A worktree is a second working directory backed by the same repository. Git has shipped the mechanism since 2015 and almost nobody used it, because humans work on one thing at a time. Agents do not, and that changed the arithmetic.

By the Continuum team. We build a workbench that runs Claude Code, Codex, and their peers, so the model rates quoted here are the ones our own cost analytics ship with.

The short version

A git worktree is an additional working directory attached to one repository. Each worktree checks out its own branch and keeps its own HEAD and index, while commits, branches, tags, remotes and config are shared through a single object database. Switching branches becomes cd, which is what makes running several coding agents at once safe.

What you need to know
  • One repository, several working directories, one shared object database.
  • Each worktree checks out its own branch. Git refuses to check one out twice.
  • Objects, branches, tags, remotes, hooks and the stash are shared. HEAD, the index and ignored files are not.
  • In a linked worktree, .git is a file containing a pointer, not a directory.
  • Switching branches becomes cd, with no stashing and no rebuild.
  • That is what makes parallel agents safe rather than merely fast.

What a worktree actually is

A git worktree is an additional working directory attached to an existing repository. You create one with git worktree add, it checks out a branch of its own, and it shares every commit, branch, tag and remote with the directory you created it from. A normal clone is one repository plus one working directory. A worktree splits that: one repository, many working directories.

Before and after, on disk.
BEFORE                        AFTER

~/code/app/                   ~/code/app/          (main)
  .git/        <- directory     .git/              <- the repository
  src/                          src/
                              ~/code/app-auth/     (feature/auth)
one directory,                  .git               <- a FILE, not a directory
one branch at a time            src/
                              ~/code/app-search/   (feature/search)
                                .git
                                src/

In the new directory, .git is not a directory. It is a one-line text file holding a pointer back into the original repository, and that indirection is the entire trick.

Verified on git 2.54, August 2026.
$ cat ../app-auth/.git
gitdir: /Users/you/code/app/.git/worktrees/app-auth

$ git -C ../app-auth rev-parse --git-dir
/Users/you/code/app/.git/worktrees/app-auth

$ git -C ../app-auth rev-parse --git-common-dir
/Users/you/code/app/.git

Those last two commands are the clearest statement of the model there is. Every worktree has a private git directory holding its own HEAD and index, and a common git directory holding everything worth sharing. That split is the whole feature.

What is shared and what is private, per the git-worktree manual.

ThingShared?Consequence
Commits and objectsYesNo duplicated history; a worktree costs a checkout, not a clone
Branches and tagsYesA commit made in one is immediately visible in all
Remotes and fetchesYesFetch once, every worktree sees it
Repository git configYesUnless you enable extensions.worktreeConfig
HooksYesOne post-checkout hook serves every worktree
The stashYesOne shared stack; git stash list is identical everywhere
HEAD, index, logs/HEADNoEach worktree has its own checkout state
refs/bisect, refs/worktree, refs/rewrittenNoA bisect or rebase in one does not disturb another
Working filesNoThat is the point
node_modules, .env, build outputNoIgnored files are not tracked, so git cannot check them out

Look inside one

The private half lives under .git/worktrees/<name>/ in the original repository. It is small, it is plain files, and reading it removes most of the mystery.

$ ls .git/worktrees/app-auth/
commondir
gitdir
HEAD
index
logs
ORIG_HEAD
refs

$ cat .git/worktrees/app-auth/commondir
../..

$ cat .git/worktrees/app-auth/gitdir
/Users/you/code/app-auth/.git

The two files that hold a worktree together.

FileLives inPoints at
.gitThe worktree directoryThe admin directory in the repository
gitdirThe admin directoryBack at the worktree .git file
commondirThe admin directoryThe shared repository (usually ../..)

The one rule that surprises people

Git will not check out the same branch in two worktrees. You meet this within about five minutes of starting.

The exact message, on Git 2.43 and newer.
$ git worktree add ../app-auth feature/auth
Preparing worktree (checking out 'feature/auth')
fatal: 'feature/auth' is already used by worktree at '/Users/you/code/app-auth'

# On Git 2.42 and older the same refusal read:
# fatal: 'feature/auth' is already checked out at '/Users/you/code/app-auth'

The wording was changed in Git 2.43 because a branch being bisected or rebased is protected by the same code path, and calling that "checked out" confused people. The behaviour is unchanged: one branch, one worktree.

It is a feature rather than a limitation. Two directories on one branch with different working states means two places committing to a single ref, which diverges the moment either of them commits. Git declines to create that situation.

What to do instead.

You wantUse
A new branch to work ongit worktree add -b feature/x ../app-x
A read-only look at a tag or commitgit worktree add --detach ../app-v1 v1.0.0
A local branch tracking a remote onegit worktree add -b pr-42 ../app-r origin/pr-42
To override the refusal anyway--force, and you will regret it

Worktree, clone, or just switch branches

Three ways to have a second thing checked out. They are not interchangeable, and the differences are mostly about cost and about whether the two things can be worked on at the same time.

The same job, three arrangements.

Switch branchesSecond cloneWorktree
Disk costNothingHistory plus files, twiceFiles only
Creation timeInstantA full cloneA checkout
Remotes to keep in syncOneTwoOne
Commit visible in the othern/aOnly after a push and fetchImmediately
Two things at onceNoYesYes
Branch lists drift apartn/aYesNo
Dependencies installedOnceOnce per cloneOnce per worktree

Switching is right for sequential work, which is most work. A second clone is right when you genuinely want an independent repository, for example a build agent that should not see your local refs. A worktree is right when you want the same repository in two places at once, which is the case that used to be rare.

Why it suddenly matters

Before coding agents, the case for worktrees was moderate. Review a colleague branch without stashing. Keep a long build running while you work elsewhere. Real, but a convenience, and stashing covered most of it.

An agent changes the arithmetic completely, because it edits files on its own while you are not watching. Two agents in one working directory is not a workflow problem, it is a correctness problem. They write the same files with no coordination, one overwrites the other, and neither reports an error. You find out later, in a diff that does not make sense, and you cannot reconstruct which agent did what.

Three concurrent tasks, two arrangements.

One directoryOne worktree each
Agents editing simultaneouslyCollide silentlyIsolated
Test runsInterfereIndependent
Reviewing a diffEverything mixed togetherOne branch, one diff
Abandoning one taskUntangle it by handgit worktree remove
MergingUntangle first, then one PRThree ordinary pull requests
Disk costOne checkoutN checkouts

Questions people ask

A second working directory backed by the same repository. Each worktree checks out its own branch and keeps its own HEAD and index, while commits, branches, tags and remotes are shared through one object database.

A clone duplicates the entire history and gets its own remotes, so the two repositories drift apart and a commit in one is invisible in the other until you push and fetch. A worktree shares the repository, so it is far cheaper to create and a commit in one is visible in all of them immediately.

No. Git refuses with "is already used by worktree at", because two directories committing to one ref diverge as soon as either commits. Create a new branch with -b, or use --detach for a read-only look at a commit.

That is how a linked worktree points back at its repository. The file contains one line, gitdir: followed by the path to the worktree admin directory under .git/worktrees. Run git rev-parse --git-common-dir to see the shared repository it resolves to.

No. Worktrees carry tracked files only, and node_modules and .env are gitignored, so git does not have them to check out. You install dependencies and copy environment files per worktree, usually from a script or a post-checkout hook.

Yes. The stash is a single shared stack, so git stash list shows the same entries in every worktree. That is confusing enough in practice that commits on a throwaway branch are a better habit once you have several worktrees.

They are the mechanism that makes it safe. Two agents in one working directory overwrite each other with no error and no warning. One worktree each gives every agent its own files, its own branch and its own diff.

The checkout is cheap because the object database is shared, so you pay for source files and nothing else. The real cost is per-worktree dependency directories, which a content-addressed package manager such as pnpm reduces to hard links.

Sources

Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.

  1. git-worktree manual
  2. Pro Git book
  3. Git 2.43 release notes the reworded in-use message
Try it

A worktree
per agent.

Continuum creates the worktree and branch for every session automatically, with a diff pane each.

free app · your subscriptions · local-first