Git Worktree
A Git feature that allows multiple branches from the same repository to be checked out simultaneously into separate working directories. In AI-assisted programming workflows, it is used to achieve task isolation across multiple concurrent coding environments.
Core Facts
Git WorkTree is a native feature introduced in Git 2.5 that allows multiple working directories to be checked out from the same repository.
Deleting a worktree should use git worktree remove rather than directly rm -rf, otherwise metadata will remain in .git/worktrees and need to be cleaned up with git worktree prune.
Compared with multiple git clones, Git worktrees save disk space and network bandwidth, provide file-system-level isolation, and allow multiple agents to work in parallel on different branches.
Timeline (last 90 days)
The same branch cannot be checked out into two Git worktrees at the same time.
A more robust approach is to provide a fully independent runtime for each Git worktree (for example, launching a dedicated database container via Docker Compose) and manage the lifecycle with idempotent scripts.
Worktrees solve isolation at the file system and version control level, the port and database scheme solves runtime isolation, and scripting solves reproducibility; only the combination of the three constitutes an ideal Agent runtime environment.
Commits, branch creation, and merges in any one worktree are immediately reflected in the other worktrees, with no need to relay through a remote repository.
When initializing worktrees, you can allocate a port range to each instance (for example, 3000-3003 for four worktrees) and inject it in the `.env` file or startup script.
Deleting a worktree should use git worktree remove rather than directly rm -rf, otherwise metadata will remain in .git/worktrees and need to be cleaned up with git worktree prune.
Compared with multiple git clones, Git worktrees save disk space and network bandwidth, provide file-system-level isolation, and allow multiple agents to work in parallel on different branches.
All Facts (8)
Git WorkTree is a native feature introduced in Git 2.5 that allows multiple working directories to be checked out from the same repository.
80%VerifiedDeleting a worktree should use git worktree remove rather than directly rm -rf, otherwise metadata will remain in .git/worktrees and need to be cleaned up with git worktree prune.
65%VerifiedCompared with multiple git clones, Git worktrees save disk space and network bandwidth, provide file-system-level isolation, and allow multiple agents to work in parallel on different branches.
65%UnverifiedWhen initializing worktrees, you can allocate a port range to each instance (for example, 3000-3003 for four worktrees) and inject it in the `.env` file or startup script.
50%UnverifiedA more robust approach is to provide a fully independent runtime for each Git worktree (for example, launching a dedicated database container via Docker Compose) and manage the lifecycle with idempotent scripts.
50%UnverifiedWorktrees solve isolation at the file system and version control level, the port and database scheme solves runtime isolation, and scripting solves reproducibility; only the combination of the three constitutes an ideal Agent runtime environment.
50%UnverifiedCommits, branch creation, and merges in any one worktree are immediately reflected in the other worktrees, with no need to relay through a remote repository.
50%UnverifiedThe same branch cannot be checked out into two Git worktrees at the same time.
50%