worktree-feature-execution
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWorktree Feature Execution
工作树功能执行流程
Purpose
目标
Execute feature delivery in isolated git worktrees with consistent automation for branch creation, synchronization, pull request creation, merge safety, and cleanup. Use this skill to reduce branch switching, minimize cross-feature interference, and maintain a clean integration path into .
main在隔离的git工作树中执行功能交付,实现分支创建、同步、拉取请求(PR)创建、安全合并和清理的自动化流程。使用本技能可减少分支切换操作,最小化跨功能干扰,保持向分支集成的路径整洁。
mainHarness Contract
协作约定
Read project instructions from first. Read second when present. Prefer AGENTS-defined conventions over CLAUDE-specific conventions.
AGENTS.mdproject.yamlUse this directory resolution priority unless the project explicitly overrides it:
- Existing
.worktrees/ - Existing
worktrees/ - Config value from
project.yaml - Default
.worktrees/
For project-local roots ( or ), verify ignore coverage before worktree creation. Add ignore entries when missing.
.worktrees/worktrees/首先从中读取项目说明,若存在则其次读取该文件。优先遵循AGENTS中定义的约定,而非Claude专属约定。
AGENTS.mdproject.yaml除非项目明确覆盖,否则使用以下目录解析优先级:
- 已存在的
.worktrees/ - 已存在的
worktrees/ - 中的配置值
project.yaml - 默认的
.worktrees/
对于项目本地根目录(或),在创建工作树前需验证忽略规则是否覆盖。若缺失则添加忽略条目。
.worktrees/worktrees/Operating Principles
操作原则
- Keep one feature per worktree and one branch per worktree.
- Keep branch names predictable and slug-safe.
- Keep PRs small and short-lived.
- Rebase frequently to reduce conflict depth.
- Run quality checks before PR creation and before merge.
- Avoid destructive git actions.
- 每个工作树对应一个功能,每个工作树对应一个分支。
- 保持分支名称可预测且符合slug规范。
- 保持PR内容精简、生命周期短。
- 经常执行变基操作以减少冲突深度。
- 在创建PR和合并前运行质量检查。
- 避免执行破坏性的git操作。
Command Resources
命令资源
Use bundled scripts in for deterministic execution:
scripts/- - repository, branch, remote, and
scripts/preflight-check.shreadiness checks.gh - - branch + worktree creation with ignore safeguards.
scripts/create-worktree.sh - - fetch + rebase branch onto base branch.
scripts/sync-worktree.sh - - compatibility-aware PR body generation.
scripts/generate-pr-body.sh - - push and create or reuse pull requests.
scripts/open-pr.sh - - merge pull request with checks and queue support.
scripts/merge-pr.sh - - safe worktree removal and prune.
scripts/cleanup-worktree.sh - - orchestration wrapper for preflight to PR (and optional merge).
scripts/run-feature-flow.sh - - Windows wrapper for safer script invocation.
scripts/windows/run-feature-flow.cmd - - Windows environment diagnostics for
scripts/windows/doctor.cmd,git, andgh.bash
All core scripts support machine-readable output using .
--json使用目录下的捆绑脚本确保执行结果一致:
scripts/- - 仓库、分支、远程仓库和
scripts/preflight-check.sh工具的就绪性检查。gh - - 带忽略规则防护的分支+工作树创建脚本。
scripts/create-worktree.sh - - 拉取远程更新并将分支变基到基准分支。
scripts/sync-worktree.sh - - 生成兼容型PR正文内容。
scripts/generate-pr-body.sh - - 推送分支并创建或复用拉取请求。
scripts/open-pr.sh - - 带检查和队列支持的PR合并脚本。
scripts/merge-pr.sh - - 安全删除工作树并清理过时元数据。
scripts/cleanup-worktree.sh - - 从预检到PR创建(及可选合并)的流程编排脚本。
scripts/run-feature-flow.sh - - Windows环境下的安全脚本调用包装器。
scripts/windows/run-feature-flow.cmd - - Windows环境下
scripts/windows/doctor.cmd、git和gh的诊断脚本。bash
所有核心脚本支持通过参数输出机器可读格式。
--jsonOne-Command Orchestration
一键式流程编排
Run the complete flow from the repository root:
bash
bash .agents/skills/worktree-feature-execution/scripts/run-feature-flow.sh \
--feature "add billing retries" \
--base "current-branch" \
--pr-base "main" \
--prefix "feat" \
--summary "Improve retry reliability for transient payment failures"Optional flags:
- to create draft PR.
--draft - to queue merge after PR creation.
--merge --queue --merge-method squash - to stop after worktree creation and sync.
--no-pr - to control setup behavior.
--setup auto|none|"<custom command>" - to append closing issue reference in PR body.
--issue <number>
Windows invocation example:
cmd
.agents\skills\worktree-feature-execution\scripts\windows\run-feature-flow.cmd --feature "add billing retries"在仓库根目录执行完整流程:
bash
bash .agents/skills/worktree-feature-execution/scripts/run-feature-flow.sh \
--feature "add billing retries" \
--base "current-branch" \
--pr-base "main" \
--prefix "feat" \
--summary "Improve retry reliability for transient payment failures"可选参数:
- - 创建草稿PR。
--draft - - PR创建后将其加入合并队列。
--merge --queue --merge-method squash - - 在工作树创建和同步后停止流程。
--no-pr - - 控制初始化行为。
--setup auto|none|"<custom command>" - - 在PR正文中添加关联的Issue关闭引用。
--issue <number>
Windows环境调用示例:
cmd
.agents\skills\worktree-feature-execution\scripts\windows\run-feature-flow.cmd --feature "add billing retries"Standard Workflow
标准工作流
1) Preflight
1) 预检
Run:
bash
bash .agents/skills/worktree-feature-execution/scripts/preflight-check.shVerify:
- Current directory belongs to a git repository.
- Base branch can be resolved.
- remote exists.
origin - is installed and authenticated.
gh - and
gitexecutable paths resolve correctly.gh - Current shell context is reported for diagnostics.
If authentication or permissions fail, stop and report the blocking condition.
执行:
bash
bash .agents/skills/worktree-feature-execution/scripts/preflight-check.sh验证内容:
- 当前目录属于git仓库。
- 基准分支可解析。
- 远程仓库存在。
origin - 工具已安装并完成认证。
gh - 和
git的可执行文件路径可正确解析。gh - 报告当前shell上下文用于诊断。
若认证或权限验证失败,立即停止并报告阻塞问题。
2) Create Isolated Worktree
2) 创建隔离工作树
Run:
bash
bash .agents/skills/worktree-feature-execution/scripts/create-worktree.sh \
--feature "add billing retries" \
--base "current-branch" \
--prefix "feat"Behavior:
- Resolve base branch from current branch when .
--base current-branch - Resolve worktree root using priority order.
- Ensure root is gitignored when local to repository.
- Create branch if missing, or reuse existing branch.
feat/<slug> - Create worktree path .
<root>/<slug>
Useful flags:
- to fail instead of mutating
--no-gitignore-edit..gitignore - to display the exact ignore line before apply.
--print-ignore-patch
执行:
bash
bash .agents/skills/worktree-feature-execution/scripts/create-worktree.sh \
--feature "add billing retries" \
--base "current-branch" \
--prefix "feat"行为说明:
- 当使用时,从当前分支解析基准分支。
--base current-branch - 按优先级顺序解析工作树根目录。
- 若根目录在仓库本地,确保已被git忽略。
- 若分支不存在则创建,否则复用现有分支。
feat/<slug> - 创建工作树路径。
<root>/<slug>
实用参数:
- - 若
--no-gitignore-edit需要修改则直接失败,而非自动修改。.gitignore - - 在应用前显示要添加的忽略规则内容。
--print-ignore-patch
3) Implement Feature
3) 功能实现
Perform implementation inside the created worktree path only. Keep scope aligned with the feature statement.
Recommended checks:
- Type checks
- Unit/integration tests
- Build command
Record notable changes and compatibility concerns for PR body.
仅在创建的工作树路径内进行功能实现。保持实现范围与功能描述一致。
推荐执行的检查:
- 类型检查
- 单元/集成测试
- 构建命令
记录重要变更和兼容性问题,用于PR正文。
4) Sync With Base Branch
4) 与基准分支同步
Run in the worktree:
bash
bash .agents/skills/worktree-feature-execution/scripts/sync-worktree.sh \
--base "main"Behavior:
- Fetch remote updates.
- Rebase feature branch on top of latest base branch.
- Stop on conflicts and report exact conflict files.
在工作树中执行:
bash
bash .agents/skills/worktree-feature-execution/scripts/sync-worktree.sh \
--base "main"行为说明:
- 拉取远程仓库更新。
- 将功能分支变基到最新的基准分支。
- 若遇到冲突则停止,并报告具体的冲突文件。
5) Open Pull Request
5) 创建拉取请求
Run in the worktree:
bash
bash .agents/skills/worktree-feature-execution/scripts/open-pr.sh \
--base "main" \
--title "feat: add billing retry policy" \
--body-file ".git/PR_BODY.md"Behavior:
- Push branch with upstream tracking if needed.
- Reuse open PR when one already exists.
- Auto-generate PR body file when missing.
- Create PR when missing.
- Validate PR body is non-empty after create/update.
- Return PR URL.
在工作树中执行:
bash
bash .agents/skills/worktree-feature-execution/scripts/open-pr.sh \
--base "main" \
--title "feat: add billing retry policy" \
--body-file ".git/PR_BODY.md"行为说明:
- 若需要则推送分支并设置上游跟踪。
- 若已有打开的PR则复用该PR。
- 若PR正文文件缺失则自动生成。
- 若不存在PR则创建新PR。
- 验证PR正文在创建/更新后非空。
- 返回PR的URL。
5a) Generate PR Body Template
5a) 生成PR正文模板
Run in the worktree:
bash
bash .agents/skills/worktree-feature-execution/scripts/generate-pr-body.sh \
--base "main" \
--feature "add billing retries" \
--risk "medium" \
--output ".git/PR_BODY.md"Behavior:
- Build compatibility-aware PR content from git diff context.
- Include commit and changed-file counts against base.
- Add risk and rollback sections.
在工作树中执行:
bash
bash .agents/skills/worktree-feature-execution/scripts/generate-pr-body.sh \
--base "main" \
--feature "add billing retries" \
--risk "medium" \
--output ".git/PR_BODY.md"行为说明:
- 基于git diff上下文生成兼容型PR内容。
- 包含相对于基准分支的提交数和文件变更数。
- 添加风险评估和回滚方案章节。
6) Merge Pull Request
6) 合并拉取请求
Run:
bash
bash .agents/skills/worktree-feature-execution/scripts/merge-pr.sh \
--pr "<url-or-number>" \
--method "squash" \
--queueBehavior:
- Validate merge method.
- Confirm checks status.
- Queue merge () when requested.
--auto - Delete remote branch after merge when supported.
执行:
bash
bash .agents/skills/worktree-feature-execution/scripts/merge-pr.sh \
--pr "<url-or-number>" \
--method "squash" \
--queue行为说明:
- 验证合并方法的有效性。
- 确认检查状态是否通过。
- 若请求则将合并加入队列()。
--auto - 合并后若支持则删除远程分支。
7) Cleanup
7) 清理
Run:
bash
bash .agents/skills/worktree-feature-execution/scripts/cleanup-worktree.sh \
--path ".worktrees/add-billing-retries"Behavior:
- Refuse cleanup when uncommitted changes exist unless .
--force - Remove worktree and prune stale metadata.
执行:
bash
bash .agents/skills/worktree-feature-execution/scripts/cleanup-worktree.sh \
--path ".worktrees/add-billing-retries"行为说明:
- 若存在未提交变更则拒绝清理,除非使用参数。
--force - 删除工作树并清理过时元数据。
Multi-Agent Coordination
多Agent协同
Use one worktree per agent. Assign explicit ownership boundaries by directory, module, or capability.
Execution order:
- Merge foundational PRs first.
- Rebase dependent PRs after each upstream merge.
- Re-run checks after every rebase.
- Merge dependent PRs only after compatibility verification.
For shared contracts (API/schema/event payloads), include compatibility notes in PR body and require contract tests.
每个Agent使用一个独立工作树。按目录、模块或功能明确划分所有权边界。
执行顺序:
- 优先合并基础功能的PR。
- 每次上游分支合并后,对依赖PR执行变基操作。
- 每次变基后重新运行检查。
- 仅在兼容性验证通过后合并依赖PR。
对于共享契约(API/ schema/事件负载),需在PR正文中添加兼容性说明,并要求执行契约测试。
Serialization Rule
序列化规则
Do not run mutating git commands in parallel. Serialize all operations that write git state (, , , , , , ). Parallelize read-only commands only.
addcommitstashcheckoutworktree add/removerebasemerge不要并行执行会修改git状态的命令。所有会写入git状态的操作(、、、、、、)都需串行执行。仅可并行执行只读命令。
addcommitstashcheckoutworktree add/removerebasemergeWindows Compatibility
Windows兼容性
Prefer Git Bash for all scripts on Windows. In restricted runners, use explicit wrapper commands under .
.shscripts/windows/Recommended sequence:
- Run .
scripts/windows/doctor.cmd - Fix PATH for ,
git, andghif missing.bash - Run .
scripts/windows/run-feature-flow.cmd
When is not in PATH, set to an explicit location.
bashGIT_BASHbash.exe在Windows环境下优先使用Git Bash运行所有脚本。在受限运行环境中,使用目录下的显式包装器命令。
.shscripts/windows/推荐执行顺序:
- 运行。
scripts/windows/doctor.cmd - 若、
git和gh的路径缺失则修复PATH配置。bash - 运行。
scripts/windows/run-feature-flow.cmd
若不在PATH中,需将设置为的明确路径。
bashGIT_BASHbash.exeManual Fallback Checklist
手动回退检查清单
Use this fallback path when orchestration cannot run end-to-end:
- Run preflight.
- Create worktree.
- Sync worktree with base branch.
- Generate PR body.
- Open PR using .
--body-file - Merge only after checks pass.
- Clean up worktree.
当编排脚本无法端到端运行时,使用以下回退流程:
- 执行预检。
- 创建工作树。
- 将工作树与基准分支同步。
- 生成PR正文。
- 使用参数创建PR。
--body-file - 仅在检查通过后合并PR。
- 清理工作树。
Edge Cases
边缘情况处理
Detached HEAD
分离HEAD状态
Resolve base branch using fallback. Stop when neither current branch nor remote default branch can be resolved.
origin/HEAD使用作为基准分支的回退方案。若当前分支和远程默认分支均无法解析则停止操作。
origin/HEADExisting Branch Already Checked Out
分支已被检出
If branch is already attached to another worktree, stop and select a new branch name or reuse that worktree.
若分支已关联到其他工作树,则停止操作并提示选择新分支名称或复用该工作树。
Worktree Path Exists
工作树路径已存在
Refuse creation when target path exists and is non-empty.
若目标路径已存在且非空,则拒绝创建工作树。
Missing Ignore Rule
忽略规则缺失
Append missing root ignore entry to before creating local worktree roots.
.gitignore在创建本地工作树根目录前,向添加缺失的根目录忽略条目。
.gitignoreDiverged Branches
分支分叉
Require rebase and conflict resolution before PR creation.
要求在创建PR前执行变基和冲突解决。
Existing PR
PR已存在
Return existing PR URL instead of creating duplicate PR.
返回已存在的PR URL,而非创建重复PR。
CI Failures
CI检查失败
Do not merge. Report failed checks and keep worktree active for remediation.
不执行合并操作。报告失败的检查项,并保持工作树活跃以便修复问题。
Merge Queue Enabled
合并队列已启用
Use flow and avoid direct merge bypass.
--queue使用流程,避免直接绕过队列进行合并。
--queuePermission Errors
权限错误
Stop and report required scope or repository role.
gh停止操作并报告所需的权限或仓库角色。
ghRed Flags
注意事项
Never:
- Run or force-push to
git reset --hard.main - Merge with known failing checks.
- Delete worktree containing uncommitted work without explicit force signal.
- Create worktrees in unignored project-local directories.
Always:
- Run preflight before worktree creation.
- Run sync before PR and before merge.
- Surface PR URL and merge status.
- Clean up merged worktrees.
绝对禁止:
- 对分支执行
main或强制推送操作。git reset --hard - 合并已知检查失败的PR。
- 在未收到明确信号时,删除包含未提交变更的工作树。
--force - 在未被忽略的项目本地目录中创建工作树。
必须执行:
- 在创建工作树前执行预检。
- 在创建PR和合并前执行同步操作。
- 提供PR URL和合并状态。
- 合并完成后清理工作树。
Additional Resources
附加资源
Reference files:
references/branch-naming.mdreferences/conflict-playbook.mdreferences/merge-policy.mdreferences/pr-template.mdCHANGELOG.mdVERSION
参考文件:
references/branch-naming.mdreferences/conflict-playbook.mdreferences/merge-policy.mdreferences/pr-template.mdCHANGELOG.mdVERSION