一键导入
git-worktree
Git Worktree: parallel working trees for isolated branch-level execution, debugging, and safe experimentation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Git Worktree: parallel working trees for isolated branch-level execution, debugging, and safe experimentation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Durable project-memory rules for `.agent-memory/` plus session-memory boundaries.
Planning-track selection, epic/feature decomposition, readiness gates, and plan-delta rules.
Shared contract for independent review agents and durable review findings.
Review routing, independent post-implementation review gates, multi-model escalation, and targeted optimization follow-up.
Independent evaluation protocol for bounded self-improvement candidate proposals.
Governance rules for bounded self-improvement candidates, promotion gates, and rollback policy.
| name | git-worktree |
| description | Git Worktree: parallel working trees for isolated branch-level execution, debugging, and safe experimentation. |
| license | See repository LICENSE |
| user-invocable | false |
Git worktree allows attaching multiple working trees to a single repository. Each worktree operates on its own branch independently, enabling true parallel development without stashing, switching, or risking merge conflicts in the working directory.
In the context of this multi-agent workflow, worktrees are used conditionally — only when the standard file-ownership parallelization strategy is insufficient.
Use worktrees for filesystem isolation and /delegate for session isolation. They complement each other rather than replacing each other.
# Create a new worktree with a new branch
git worktree add <path> -b <new-branch-name> [<start-point>]
# Example: create a worktree for feature work
git worktree add ../project-feature-auth -b feature/auth main
# Create a worktree on an existing branch
git worktree add <path> <existing-branch>
git worktree list
# Output:
# /path/to/main-repo abc1234 [main]
# /path/to/project-feature def5678 [feature/auth]
# Remove after work is done
git worktree remove <path>
# Force remove (if worktree has uncommitted changes)
git worktree remove --force <path>
# Clean up references to manually deleted worktrees
git worktree prune
The Orchestrator is the sole owner of worktree lifecycle. Coding agents work within worktrees but do NOT create or remove them.
Orchestrator creates a worktree before delegating:
# Convention: sibling directory, descriptive name
git worktree add ../<project>-wt-<purpose> -b wt/<purpose> <base-branch>
Branch naming convention: wt/<purpose> (e.g., wt/feature-auth, wt/debug-login-crash, wt/refactor-api-layer).
Path convention: sibling directory ../<project>-wt-<purpose>.
Orchestrator delegates the task to the coding agent with:
The coding agent:
After agent completes and Reviewer approves:
# Orchestrator merges from main worktree
git merge wt/<purpose>
# Or cherry-pick specific commits
git cherry-pick <commit-hash>
Orchestrator MUST clean up after merge:
git worktree remove ../<project>-wt-<purpose>
git branch -d wt/<purpose>
CRITICAL: Never leave worktrees dangling. Every created worktree must be removed after its purpose is fulfilled.
If a worktree path still exists but is locked:
git worktree unlock <path>
git worktree remove <path>
All worktrees share the same .git directory. This means:
If the project uses submodules, they must be initialized separately in each worktree:
cd <worktree-path>
git submodule update --init --recursive
Each worktree has its own working tree — node_modules, build artifacts, virtual environments, etc. must be installed independently:
cd <worktree-path>
npm install # or pip install, etc.
When two independent features must modify the same files (e.g., both touch App.tsx):
Main worktree: stays on main branch (Orchestrator control)
Worktree A: wt/feature-auth → Coder works on auth
Worktree B: wt/feature-dashboard → Coder works on dashboard
After both complete → Orchestrator merges sequentially, resolving conflicts if any.
Debugger needs a clean tree to reproduce without in-progress changes:
Main worktree: feature work in progress
Worktree debug: wt/debug-issue-42 → Debugger reproduces and fixes
After fix → merge back, remove worktree.
High-risk structural change that might need to be rolled back:
Main worktree: stable state preserved
Worktree refactor: wt/refactor-api-v2 → Coder performs refactoring
If refactoring passes review → merge. If it fails → simply remove the worktree, no damage done.
/delegateWhen a task is both long-running and likely to overlap with ongoing work:
.agent-memory/ before the branch is closedAfter every worktree session, Orchestrator must verify:
git worktree remove)git branch -d)git worktree prune)Use this section when the Orchestrator is deciding whether to introduce a worktree.
At least one is true:
All are true: