Definition
A git worktree is an additional working directory attached to the same Git repository, with its own checked-out branch and files but a shared history, created with `git worktree add`.
Also called: worktree, linked worktree.
Normally a repository has one working folder, so switching tasks means stashing or committing and checking out another branch. A worktree gives you a second (or tenth) folder instead, each on its own branch, all sharing one .git store, so commits made in one are visible from the others. Git won't normally check out the same branch in two worktrees at once.
git worktree add ../acme-api-login -b fix-login # new folder on a new branch
git worktree list # see all worktrees
git worktree remove ../acme-api-login # delete it when doneWorktrees matter for AI coding agents because two agents editing the same folder trip over each other's changes. Giving each one its own worktree keeps their edits apart. Claude Code's claude --worktree <name> creates one under .claude/worktrees/<name>/ on a new branch, and a subagent with isolation: worktree gets a temporary one. A new worktree is a fresh checkout: dependencies need installing, and gitignored files such as .env aren't there unless copied in.
In Pairbar
The composer's Worktree chip starts a new chat on a new branch in a separate worktree, so your current checkout isn't touched; the worktree is named after what you typed. The workflow docs also suggest running Can run commands steps in a clean checkout or a worktree, since commands can still change files. See the composer.
Frequently asked questions
- Is a git worktree the same as a clone?
- No. A clone copies the whole repository; a worktree is another working folder of the same repository, sharing its history, branches and objects.
- Can two worktrees use the same branch?
- Not normally. Git refuses to check out a branch that's already checked out in another worktree unless you force it.
- Why do AI agents use worktrees?
- So several agents can work on one repository at once without editing the same files in the same folder.
Related
- Use caseStart a Claude Code or Codex chat on a new branch in its own git worktreePairbar's composer starts a chat in any repo, on any branch or in a new worktree, with model, effort, mode, agent and local or cloud set up front.
- Use caseRun several Claude Code and Codex agents in parallel without losing trackA Needs you section, live activity lines, subagent chips, worktrees and ⌃1–9 for running many agents at once.
- GlossarySubagentA helper agent a main coding agent starts for one piece of work, with its own context, returning only a summary.
- DocsNew chatsThe composer: app, folder, branch, worktree, agent, skills, model, effort, mode, cloud; searchable pickers, remembered choices, and the Claude-or-Codex suggestion