[KongchangAI]
ConceptGit Worktrees / Git Worktree

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

Timeline (last 90 days)

Oct 24

The same branch cannot be checked out into two Git worktrees at the same time.

Unverified50%
Oct 24

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.

Unverified50%
Oct 24

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.

Unverified50%
Oct 24

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.

Unverified50%
Oct 24

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.

Unverified50%
Oct 12

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.

Verified65%
Aug 29

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.

Verified65%

All Facts (8)

Source Articles