Guide

Git worktrees, explained

A worktree gives one repository a second working directory with its own checked-out branch, so you can work on two branches at the same time without cloning again. This guide covers the commands, the errors you'll hit, and which Git GUIs support worktrees.

By Kris · Updated September 2026 · Applies to git 2.5 and later

What is a git worktree?

Every repository starts with one working directory. git worktree add attaches more. Each worktree is a real directory with real files and its own checked-out branch, and all of them share the same repository underneath: one object database, one set of branches and tags, one stash list. Commit in one worktree and the commit is immediately visible in the others.

A linked worktree is cheap because it holds no second copy of the repository. Its .git is a plain file pointing back at .git/worktrees/<name> in the main checkout. That is also why git always knows which worktrees exist: git worktree list reads those records, and git worktree prune deletes stale ones.

The classic uses: fix an urgent bug on main while a feature branch sits mid-refactor in your main checkout, run a long test suite on one branch while you edit another, or check out a colleague's branch next to yours to review it. The newer use is coding agents, which create worktrees so several sessions can run in parallel without touching your checkout.

Worktree vs branch

A branch is a line of history; a worktree is a place on disk where a branch is checked out. Switching branches reuses one directory and one set of build artifacts, and asks you to stash or commit first. A worktree gives the second branch its own directory, so both exist at once, each with its own editor window, dev server or test run. Switch branches for quick hops; add a worktree when both branches need to be running at the same time.

Worktree vs a second clone

A second git clone also gives you a second directory, but it duplicates the entire object database, fetches independently, and its branches drift from your first clone's. A worktree shares everything: it costs almost no disk, needs no extra fetching, and a commit made in one worktree is immediately on the shared repository. The only things a clone isolates that a worktree doesn't are the config and the remotes, and that's rarely what you want isolated.

How to use git worktree: add, list, remove, prune

Everything is a subcommand of git worktree. The path you pass is where the new directory is created; sibling directories keep things tidy.

# new worktree, new branch named after the directory (from HEAD)
$ git worktree add ../repo-review
 
# new worktree for an existing branch
$ git worktree add ../repo-hotfix hotfix-login
 
# new worktree, new branch, from a chosen start point
$ git worktree add -b fix-nav ../repo-fix-nav main
 
# see every worktree, its path, HEAD and branch
$ git worktree list
/Users/you/repo 8f2a91c [main]
/Users/you/repo-review 4d17e0b [repo-review]
/Users/you/repo-hotfix c90b3aa [hotfix-login]
 
# done with it: remove the directory and its bookkeeping
$ git worktree remove ../repo-review
 
# deleted a worktree directory by hand? clean up the records
$ git worktree prune
 
# relocate a worktree without recreating it
$ git worktree move ../repo-hotfix ../hotfix

remove refuses if the worktree has uncommitted changes; add --force to discard them. prune only deletes stale bookkeeping, never files. Two subcommands you'll want eventually: git worktree lock keeps a worktree on a removable drive from being pruned while it's unmounted, and git worktree repair fixes the back-references after you move the main repository itself.

How to remove or delete a git worktree

Delete a worktree with git worktree remove, not rm -rf. One command deletes the directory and the repository's record of it. You can run it from any worktree of the repository, including the one you're removing.

# a clean worktree: directory and record, gone
$ git worktree remove ../repo-review
 
# discard its uncommitted and untracked files as well
$ git worktree remove --force ../repo-review
 
# the branch survives removal; delete it separately
$ git branch -d repo-review
 
# the directory was already deleted by hand
$ git worktree prune

Three messages stop a removal. Each one names its fix:

Removing a worktree never deletes its branch. git branch -d deletes the branch once it's merged; git branch -D deletes it regardless. Delete the branch after the worktree, not before: git refuses to delete a branch that a worktree still has checked out.

Cheat sheet

TaskCommand
New worktree + new branchgit worktree add ../dir
Worktree for an existing branchgit worktree add ../dir branch
New branch from a start pointgit worktree add -b branch ../dir main
List worktreesgit worktree list
Machine-readable listgit worktree list --porcelain
Remove a worktreegit worktree remove ../dir
Remove, discarding local changesgit worktree remove --force ../dir
Clean up after manual deletiongit worktree prune
Move a worktreegit worktree move ../dir ../newdir
Protect from pruninggit worktree lock ../dir
Fix links after moving the repogit worktree repair

Download as PDF

The two errors everyone hits

fatal: 'branch' is already used by worktree at '...'

Git refuses to check out a branch that is already checked out in another worktree, because two working directories editing one branch would silently overwrite each other's view of it. Either go work in the worktree that already has the branch (git worktree list shows where it is), remove that worktree if it's stale, or take a new branch instead: git worktree add -b branch-2 ../dir branch.

error: cannot delete branch 'x' used by worktree at '...'

The mirror image: a branch cannot be deleted while any worktree has it checked out, and -D does not override it. Remove the worktree first (git worktree remove ../dir, or git worktree prune if the directory is already gone), then delete the branch.

Keeping worktrees tidy

Worktrees and coding agents

Worktrees stopped being a power-user trick when coding agents adopted them. Claude Code can run whole sessions and subagents in isolated worktrees, the Codex app and Cursor's agents run in worktrees of their own, and opencode runs parallel sessions the same way. In each case the agent gets a private working directory, works in parallel, and leaves a branch behind. Your job is to read what it did before it merges. The workflow, per tool, is in Claude Code worktrees, explained.

Which Git GUIs support worktrees?

Support varies more between Git GUIs than any other mainstream feature:

ClientWorktree supportShape
Meridian✓Each worktree opens in its own titled window; mrd opens the one you're standing in; create, remove, or open a branch as a worktree from the app
Fork✓Tabs inside one window; tabs can't be renamed and collide when directory names repeat
Tower✓Managed inside a single window
GitKraken✓Sidebar section inside a single window
Sublime Merge⚠︎Dev channel only; switches worktrees inside one window
GitButler⚠︎Different model: virtual branches in one workspace instead of worktrees
SourceTree✕No worktree support
GitHub Desktop✕No worktree support

A window per worktree, one command away

Meridian is a native Mac Git client built around worktrees: every one gets its own window, mrd opens whichever you're standing in, and Markdown, CSV and JSON diffs render as documents.

Free 14-day trial | One licence, three Macs

Related: Claude Code worktrees | git diff, explained | Best Git client for Mac | Meridian, a native Git client for the Mac

Kris is the founder of Meridian and spends most days in the workflow these guides cover: worktrees, diffs, and reading what the agents wrote.

Worktrees, answered

What is a git worktree, in one sentence?

A worktree is an extra working directory attached to the same repository, so two or more branches can be checked out at the same time without cloning again.

Can two worktrees check out the same branch?

No. Git refuses with "fatal: 'branch' is already used by worktree at ...". Check out a different branch, or create a new one with git worktree add -b.

Do worktrees share branches, stashes and history?

Yes. All worktrees of a repository share one object database, one set of branches and tags, and one stash list. Each worktree has its own checked-out branch, index and working files.

How do I delete a git worktree?

Run git worktree remove ../dir. It deletes the directory and git's record of it. Add --force to discard uncommitted changes. The branch stays, so delete it separately with git branch -d branch. If you already deleted the directory by hand, run git worktree prune.

Where should I put worktrees?

Outside the repository, usually as sibling directories: repo/, repo-review/, repo-hotfix/. Never create a worktree inside another worktree's directory, or the outer one will see it as untracked files.

How do I open a worktree in a Git GUI?

Most GUIs treat worktrees as tabs or sidebar entries inside one window. Meridian opens each worktree in its own titled window: cd into the worktree, type mrd, and that window is just that worktree.