> git worktree
multiple working trees on one repository — check out several branches at once, give every AI coding agent its own isolated directory, and merge the results back
// basics
8 commandsCheck out an existing branch in a new worktree
$ git worktree add ../myapp-hotfix hotfixCreate a worktree with a new branch
$ git worktree add -b feature-auth ../myapp-auth mainCreate a worktree and branch from just a path
$ git worktree add ../hotfixCreate a worktree from a remote branch
$ git fetch originCreate a throwaway worktree with a detached HEAD
$ git worktree add -d ../scratchList all worktrees and see what is checked out where
$ git worktree listCheck out the same branch in two worktrees
$ git worktree add --force ../myapp-copy feature-xCreate a worktree without checking out files
$ git worktree add --no-checkout -b agent-docs ../myapp-docs main// ai agents & parallel sessions
9 commandsRun multiple AI coding agents in parallel on one repo
$ git worktree add -b agent/auth ../myapp-agent-auth mainLet Claude Code manage the worktree for you
$ claude --worktree feature-authBatch-create worktrees for a fleet of agents
$ for t in auth search billing; do git worktree add -b agent/$t ../myapp-agents/$t main; doneCopy .env and untracked files into a new worktree
$ cp .env .env.local ../myapp-agent-auth/ 2>/dev/nullInstall dependencies in each worktree
$ pnpm install --dir ../myapp-agent-authRun each agent in its own tmux window
$ tmux new-session -d -s agents -n auth -c ../myapp-agents/authCompare what two agents produced
$ git diff main...agent/authMerge the winning agent branch back to main
$ git merge agent/authTear down an agent worktree when the task is done
$ git worktree remove --force ../myapp-agents/auth// maintenance & cleanup
6 commandsRemove a worktree safely
$ git worktree remove ../myapp-hotfixClean up after deleting a worktree folder manually
$ git worktree prune --dry-run -vMove a worktree to a new location
$ git worktree move ../myapp-hotfix ~/work/hotfixRepair worktrees after moving the repository
$ git worktree repairLock a worktree so it cannot be pruned or removed
$ git worktree lock --reason "on portable SSD" ../myapp-usbFix cannot delete branch checked out at errors
$ git worktree remove ../myapp-agents/auth// internals & scripting
6 commandsUnderstand where worktree metadata lives
$ cat ../myapp-hotfix/.gitGive one worktree its own git config
$ git config extensions.worktreeConfig trueKeep a worktree small with sparse-checkout
$ git worktree add --no-checkout -b agent-web ../myapp-web mainRead the HEAD of another worktree from anywhere
$ git rev-parse worktrees/auth/HEADScript against the worktree list in CI
$ git worktree list --porcelainStart an empty orphan branch in a new worktree
$ git worktree add --orphan -b gh-pages ../myapp-pages