Worktree

A worktree is a separate working copy of a Git repository, with its own branch and files, that shares the repository's history with other working copies.

A worktree is a folder where a branch of a Git repository is checked out. Git lets one repository have several worktrees at the same time, each on a different branch. They share one store of commits and objects, so creating a worktree is fast and takes little disk space. Changes in one worktree do not affect the files of another.

Worktrees let a developer work on several branches without switching back and forth. One worktree can hold a feature in progress while another holds a bug fix or a review. Each has its own uncommitted changes and build outputs. When the work is done, the worktree is removed and its branch can be merged.

Coding agents use worktrees to work in parallel on the same repository. Each agent gets its own worktree, so their edits do not collide. A worktree separates files, but not processes, ports, or installed packages, which all still share one machine. When agents need full separation, each one works in its own sandbox with its own copy of the repository.