Definition

Git worktree

Git worktrees let you check out multiple branches of the same repo into separate directories simultaneously — ideal for parallel AI coding agents.

Git worktrees let you have multiple branches of the same repository checked out in different directories at the same time. You keep one .git database but project several working trees from it — each is a normal directory that can build, run tests, and hold dirty changes independently. It's built-in functionality in Git, not a plugin.

Why it matters

For agentic coding, worktrees are the single best pattern for running parallel agents. Instead of one Claude Code session switching branches, you create a worktree per task and run one agent per worktree. No branch-switching, no stashing, no accidental cross-contamination.

SpaceSpider pairs naturally with worktrees: create one space per worktree, pick your CLI for each pane, and you have a fleet of isolated agentic workspaces on one machine. See /blog/git-worktrees-with-claude-code if we've published on this.

How it works

Core commands:

  • git worktree add ../myrepo-feature feature-branch — check out feature-branch into ../myrepo-feature
  • git worktree list — show all worktrees
  • git worktree remove ../myrepo-feature — delete a worktree
  • git worktree prune — clean up stale entries

Each worktree has its own index, working tree, and HEAD, but they all share the same object database and refs. You cannot check out the same branch in two worktrees at once (unless you use --force), which protects you from split-brain commits.

How it's used

Common patterns:

  • One worktree per in-flight feature branch, so you never need to stash
  • Worktree for code review — check out a PR branch without disturbing your main worktree
  • Worktree per agent — Claude Code here, Codex CLI there, each in its own directory
  • Hotfix worktree that's always checked out to main for emergency fixes
  • Space — SpaceSpider's workspace unit, pairs with worktrees
  • Agentic coding — the workload worktrees accelerate
  • Claude Code — works great one-per-worktree
  • Checkpoint — complementary safety net
  • Subagent — you can delegate a whole worktree to a subagent

FAQ

Do worktrees use extra disk?

Each working tree holds a full checkout, so disk use scales roughly linearly with number of worktrees. The .git object database is shared, which saves significantly over multiple full clones.

Can I convert an existing clone into a worktree setup?

Yes — keep your existing repo as one worktree and use git worktree add to create siblings. You don't have to re-clone.

What happens if I delete a worktree directory manually?

The worktree registration remains. Run git worktree prune to clean up stale entries.

Related terms