Loading...
Loading...
Git Worktrees enables parallel development by maintaining multiple checked-out branches simultaneously in separate directories.
npx skill4agent add itallstartedwithaidea/agent-skills git-worktreesgraph TD
A[Main Repo] --> B["git worktree add ../task-1 -b feature/task-1"]
A --> C["git worktree add ../task-2 -b feature/task-2"]
A --> D["git worktree add ../hotfix -b hotfix/urgent"]
B --> E[Agent 1 works in ../task-1]
C --> F[Agent 2 works in ../task-2]
D --> G[Agent 3 works in ../hotfix]
E --> H[PR + Merge]
F --> H
G --> H
H --> I["git worktree remove ../task-1"]
H --> J["git worktree remove ../task-2"]
H --> K["git worktree remove ../hotfix"].git# Create a worktree for a new feature
git worktree add ../feature-auth -b feature/user-auth
cd ../feature-auth
npm install # Dependencies may differ per branch
# List active worktrees
git worktree list
# /home/user/project abc1234 [main]
# /home/user/feature-auth def5678 [feature/user-auth]
# Run tests in a clean worktree
git worktree add ../clean-test --detach HEAD
cd ../clean-test
npm ci && npm test
cd ../project
git worktree remove ../clean-test
# Prune stale worktrees (after branch deletion)
git worktree pruneclass WorktreeManager:
def __init__(self, repo_root):
self.repo_root = repo_root
self.worktree_base = Path(repo_root).parent
def create(self, task_name, base_branch="main"):
branch = f"feature/{task_name}"
path = self.worktree_base / task_name
subprocess.run(
["git", "worktree", "add", str(path), "-b", branch, base_branch],
cwd=self.repo_root, check=True
)
return WorktreeContext(path, branch)
def remove(self, task_name):
path = self.worktree_base / task_name
subprocess.run(
["git", "worktree", "remove", str(path)],
cwd=self.repo_root, check=True
)
def list_active(self):
result = subprocess.run(
["git", "worktree", "list", "--porcelain"],
cwd=self.repo_root, capture_output=True, text=True
)
return self.parse_worktree_list(result.stdout)npm cinode_modulesgit worktree prune| Platform | Support | Notes |
|---|---|---|
| Cursor | Full | best-of-n-runner uses worktrees natively |
| VS Code | Full | Multi-root workspace support |
| Windsurf | Full | Shell-based worktree management |
| Claude Code | Full | Direct git access |
| Cline | Full | Terminal git commands |
| aider | Full | Works from any worktree directory |
git-worktreesparallel-developmentisolated-workspaceclean-baselineconcurrent-branchessubagent-isolationbest-of-nbranch-management