Token导航 LogoToken导航

Agent Skill · 研究检索

merge-worktree(合并工作树)

merge-worktree 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

merge-worktree 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 55,679。

总安装 470周安装 19GitHub Stars 7下载 147核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:merge-worktree(合并工作树)
来源仓库:https://github.com/nesnilnehc/ai-cortex
仓库路径:skills/merge-worktree
安装命令:
npx skills add https://github.com/nesnilnehc/ai-cortex --skill merge-worktree
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/nesnilnehc/ai-cortex --skill merge-worktree

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

merge-worktree 用于查找、检索和筛选相关信息。适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词或任务场景快速定位候选结果。通过 npx skills add 命令从指定仓库安装并使用该技能。安装前需确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写操作。

适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/merge-worktree

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/nesnilnehc/ai-cortex --skill merge-worktree;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

merge-worktree 怎么安装?

在终端执行 npx skills add https://github.com/nesnilnehc/ai-cortex --skill merge-worktree。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

merge-worktree 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

merge-worktree 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

merge-worktree 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

merge-worktree 用的人多吗?

公开数据是累计安装 470 次,近一周安装 19 次,下载 147 次,GitHub 7 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

merge-worktree 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
merge-worktree

合并工作树 · 本页

4707需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Skill: merge-worktree

Purpose

Automates the batch worktree lifecycle from the main repo: scan all active linked worktrees, let the user select which to merge, verify all selected are clean, merge and push each in sequence, then remove all successfully-merged worktrees together. Eliminates the need to cd into each worktree directory and invoke a merge operation separately.


Core Objective

Primary goal: From the main repo, land all selected worktree branches onto main, deliver them to origin, and clean up — leaving the repository in a clean state.

Success Criteria (all must be satisfied):

  1. ✅ Invocation context verified: CWD is the main repo root, not inside a linked worktree
  2. ✅ All linked worktrees discovered: git worktree list parsed; non-main worktrees presented to user
  3. ✅ Pre-flight completed before any merge: All selected worktrees checked for clean working tree; all dirty ones reported upfront
  4. ✅ Batch merge + push: Each selected clean worktree merged with --no-ff and pushed; per-worktree status (succeeded/failed) recorded
  5. ✅ Unified cleanup: All succeeded worktrees removed together; no failed worktree is deleted
  6. ✅ Summary reported: Per-worktree table covers merge, push, cleanup, and branch-deletion status for every entry

Acceptance Test: After skill completes, git log --oneline <main> shows one merge commit per succeeded worktree; git worktree list shows only the main repo and any failed/skipped worktrees; remote is up to date.


Scope Boundaries

This skill handles:

  • Verifying invocation context (main repo, not a linked worktree)
  • Detecting the main branch (auto-detect or ask user)
  • Scanning and listing all active linked worktrees
  • User selection of which worktrees to merge (all or subset)
  • Pre-flight clean-tree check for all selected worktrees before any merge begins
  • Sequential merge (--no-ff) + push for each selected clean worktree
  • Per-failure user decision: continue with remaining or abort
  • Unified cleanup of all successfully-merged worktrees
  • Optional feature branch deletion (user-confirmed, -d only)
  • Per-worktree summary report

This skill does NOT handle:

  • Committing uncommitted changes (use commit-work skill first, per worktree)
  • Rebasing or squashing commits before merge
  • Resolving merge conflicts (halts and reports to user)
  • Creating or managing pull requests
  • Pushing feature branches or creating remote tracking branches
  • Force-pushing to any branch
  • Parallel merge execution (always sequential)

Handoff points:

  • If any selected worktree is dirty → report all dirty ones upfront; ask user to continue with clean ones or halt all
  • If a merge conflict occurs → halt that worktree; ask whether to continue with remaining
  • If push is rejected → halt that worktree; ask whether to continue with remaining
  • If invoked from inside a linked worktree → halt immediately

Use Cases

  • Developer has 2–4 feature worktrees ready to land onto main and wants to handle them in one invocation
  • End-of-sprint batch cleanup: merging all completed feature worktrees from the main repo
  • CI/automation that spawned multiple parallel worktrees for isolated tasks, now collecting results
  • After completing commit-work cycles in multiple worktrees, delivering all work end-to-end

Behavior

Workflow (Checklist)

Step 1 — Verify invocation context

git rev-parse --show-toplevel          # current repo root
git worktree list --porcelain          # first worktree entry = main repo path

Parse git worktree list --porcelain. The first block is the main repo. Compare its worktree path against git rev-parse --show-toplevel.

  • If they do NOT match (currently inside a linked worktree) → halt: "This skill must be run from the main repo, not from inside a worktree. Current location: <cwd>. Main repo is at: <main-repo-path>. Run cd <main-repo-path> and re-invoke."
  • If they match → record <main-repo-path>. CWD remains here for every subsequent step.

Step 2 — Determine main branch

git remote show origin | grep 'HEAD branch'
  • Unambiguous result (e.g., HEAD branch: main) → use it.
  • Command fails or returns nothing → check git branch -r for origin/main then origin/master.
  • Still ambiguous → ask the user: "Could not determine the main branch automatically. What is the name of the main branch (e.g., main, master, develop)?"

Record <main-branch>.

Step 3 — Scan and present active worktrees

git worktree list

Parse output. Filter out the main repo entry (the one at <main-repo-path> on <main-branch>). Each remaining entry is a candidate.

  • If no linked worktrees found → halt: "No active linked worktrees found. Nothing to merge."

Present the list with path and branch name:

Active worktrees available to merge:
  [1]  /repos/myapp-auth      feat/user-auth
  [2]  /repos/myapp-api       feat/api-v2
  [3]  /repos/myapp-ui        feat/dashboard

Ask:

"Which worktrees should be merged? Enter numbers separated by commas, or type all:"

Record <selected-list>.

Step 4 — Pre-flight: check all selected worktrees

For each worktree in <selected-list>:

git -C <worktree-path> status --porcelain

Collect all results. Build <clean-list> and <dirty-list>.

If <dirty-list> is non-empty, report all dirty entries in a single block before any merge begins:

Pre-flight check — dirty worktrees (will be skipped):
  /repos/myapp-api   (feat/api-v2)    — 3 uncommitted file(s)
  /repos/myapp-ui    (feat/dashboard) — 1 uncommitted file(s)

Ask:

"The above worktrees have uncommitted changes. Proceed with the remaining clean worktrees, or halt all? [continue / halt]"
  • halt → stop; no merges performed.
  • continue → proceed with <clean-list> only. If <clean-list> is empty → halt, nothing to do.

No auto-stash is performed under any condition.

Step 5 — Batch merge + push (sequential)

For each worktree W in <clean-list>:

# Pull main to stay current across multi-worktree run
git checkout <main-branch>
git pull origin <main-branch>

# Merge with --no-ff
git merge --no-ff <W.branch> -m "Merge branch '<W.branch>' into <main-branch>"

# Push
git push origin <main-branch>

On failure for worktree W:

  • If merge conflict: "Merge conflict merging <W.branch> into <main-branch>. Resolve conflicts in <main-repo-path>, complete the merge manually, then push and remove the worktree."
  • If push rejected (non-fast-forward): "Push rejected after merging <W.branch>. Run git reset --hard HEAD~1 in <main-repo-path> to undo the merge, then pull, re-merge, and push manually."

In both cases, mark W as failed and ask:

"Continue with the remaining worktrees, or abort all remaining? [continue / abort]"
  • abort → stop; do not touch any remaining worktrees.
  • continue → mark W as failed, proceed to next.

Record per-worktree outcome: succeeded or failed.

Step 6 — Unified cleanup

After all merges complete, verify CWD is still the main repo:

pwd   # must equal <main-repo-path>

For each worktree in <succeeded-list> only:

git worktree remove <worktree-path>

Execute sequentially. If an individual removal fails (e.g., path already gone), log the error and continue.

Never remove a worktree whose status is failed.

Step 7 — Offer to delete feature branches

For all worktrees in <succeeded-list>, present branches together:

"Worktrees removed. Delete these local feature branches? Enter numbers, all, or none:" `` [1] feat/user-auth [2] feat/dashboard ``

For each confirmed:

git branch -d <W.branch>

Use -d only — never -D. If -d fails (unexpected after a successful --no-ff merge), report and stop for that branch.

Step 8 — Summary report

merge-worktree summary
──────────────────────────────────────────────────────────────────────────
Worktree               Branch            Merge         Push   Cleanup  Branch
/repos/myapp-auth      feat/user-auth    ✓             ✓      ✓        deleted
/repos/myapp-api       feat/api-v2       ✗(conflict)   —      —        —
/repos/myapp-ui        feat/dashboard    skipped(dirty) —     —        —
──────────────────────────────────────────────────────────────────────────
Main branch: main  |  Remote: origin

Status codes: ✓ succeeded · ✗(reason) failed · skipped(dirty) pre-flight fail · — not applicable


Input & Output

Input Requirements

InputRequiredDescription
Main repo contextYesCWD must be the main repo root; halts if inside a linked worktree
Active linked worktreesYesAt least one non-main linked worktree must exist
Worktree selectionUser inputall or comma-separated indices from the presented list
Clean working treePer-worktreeDirty worktrees are reported upfront and skipped; no auto-stash
Main branch nameAuto/AskDetected from remote; user asked if ambiguous
Network accessYesRequired to push to origin

Output Contract

Produces (side-effects):

ElementDescription
Merge commitsOne --no-ff merge commit on <main-branch> per succeeded worktree
Remote pushorigin/<main-branch> updated once per succeeded worktree
Worktree removalAll succeeded worktrees removed from git worktree list
Branch deletionOptional, user-confirmed; git branch -d only
Batch summary reportPer-worktree table: branch, merge, push, cleanup, branch-deletion status

Restrictions

Hard Boundaries

  • MUST NOT force-push (--force, --force-with-lease) to any branch
  • MUST NOT remove any worktree if its merge or push failed
  • MUST NOT auto-stash uncommitted changes — report upfront and skip the worktree
  • MUST NOT use git branch -D — only -d (safe delete)
  • MUST NOT begin any merge before pre-flight check completes for all selected worktrees
  • MUST NOT proceed if invoked from inside a linked worktree — halt immediately

Skill Boundaries

Do not do these (other skills or tools handle them):

  • Committing pending work: Use commit-work skill per worktree before invoking this skill
  • Rebasing/squashing: Use git rebase directly before invoking this skill
  • Creating PRs: Use platform-specific PR tools; this skill merges directly to main
  • Code review: Use review-diff before committing; this skill does not review code

Anti-Patterns

Invocation context

✅ Always run from the main repo root ❌ Do not run from inside a linked worktree — the CWD becomes invalid when the worktree is later removed, causing all subsequent commands to fail

Pre-flight order

✅ Check all selected worktrees for dirty state before starting any merge ❌ Do not check each worktree immediately before merging it — the user would discover dirty worktrees mid-batch after some merges are already committed

Merge style

✅ Use git merge --no-ff to preserve branch history ❌ Do not use git merge --squash or fast-forward merge — history would be lost

Push safety

✅ Use git push origin <main-branch> (standard push) ❌ Never use --force or --force-with-lease on main

Deletion order

✅ Remove worktrees only after their merge AND push both succeeded ❌ Do not remove a worktree after merge but before push — the branch would be unreachable if push fails

Branch deletion

✅ Use git branch -d (safe) and confirm with user first ❌ Never use git branch -D (force) — it can delete unmerged commits


Examples

Example 1: Batch happy path

Scenario: Two feature worktrees are ready to merge into main.

Execution:

# Step 1: Guard — invoked from main repo
git rev-parse --show-toplevel   # /repos/myapp
git worktree list --porcelain   # first entry: /repos/myapp → match ✓

# Step 2: Main branch
git remote show origin | grep 'HEAD branch'
# HEAD branch: main

# Step 3: Scan
git worktree list
# /repos/myapp        abc1234 [main]
# /repos/myapp-auth   def5678 [feat/user-auth]
# /repos/myapp-api    ghi9012 [feat/api-v2]
# User selects: all

# Step 4: Pre-flight
git -C /repos/myapp-auth status --porcelain   # (empty ✓)
git -C /repos/myapp-api  status --porcelain   # (empty ✓)

# Step 5: Merge + push — worktree 1
git checkout main
git pull origin main
git merge --no-ff feat/user-auth -m "Merge branch 'feat/user-auth' into main"
git push origin main

# Step 5: Merge + push — worktree 2
git pull origin main
git merge --no-ff feat/api-v2 -m "Merge branch 'feat/api-v2' into main"
git push origin main

# Step 6: Unified cleanup
pwd                                    # /repos/myapp ✓
git worktree remove /repos/myapp-auth
git worktree remove /repos/myapp-api

# Step 7: Branch deletion — user selects all
git branch -d feat/user-auth
git branch -d feat/api-v2

Summary:

merge-worktree summary
──────────────────────────────────────────────────────────────────────────
Worktree             Branch          Merge  Push  Cleanup  Branch
/repos/myapp-auth    feat/user-auth  ✓      ✓     ✓        deleted
/repos/myapp-api     feat/api-v2     ✓      ✓     ✓        deleted
──────────────────────────────────────────────────────────────────────────
Main branch: main  |  Remote: origin

Example 2: Pre-flight dirty detection (edge case — skip and continue)

Scenario: Three worktrees selected; two have uncommitted changes.

Execution:

# Step 4: Pre-flight
git -C /repos/myapp-auth  status --porcelain   # (empty ✓)
git -C /repos/myapp-api   status --porcelain   # M  src/api.ts
git -C /repos/myapp-ui    status --porcelain   # ?? src/temp.log

Skill reports:

Pre-flight check — dirty worktrees (will be skipped):
  /repos/myapp-api  (feat/api-v2)    — 1 uncommitted file(s)
  /repos/myapp-ui   (feat/dashboard) — 1 uncommitted file(s)
"Proceed with the remaining clean worktrees, or halt all? [continue / halt]"

User answers continue → only feat/user-auth is merged and cleaned up. The other two are untouched.

Summary:

merge-worktree summary
──────────────────────────────────────────────────────────────────────────
Worktree             Branch          Merge         Push  Cleanup  Branch
/repos/myapp-auth    feat/user-auth  ✓             ✓     ✓        deleted
/repos/myapp-api     feat/api-v2     skipped(dirty) —    —        —
/repos/myapp-ui      feat/dashboard  skipped(dirty) —    —        —
──────────────────────────────────────────────────────────────────────────

Example 3: Mid-batch merge conflict (edge case — continue past failure)

Scenario: Two clean worktrees; the second has a conflicting change with recent main.

Execution:

# Step 5: Worktree 1 — succeeds
git merge --no-ff feat/user-auth -m "Merge branch 'feat/user-auth' into main"
git push origin main
# ✓ succeeded

# Step 5: Worktree 2 — conflict
git merge --no-ff feat/api-v2 -m "Merge branch 'feat/api-v2' into main"
# CONFLICT (content): Merge conflict in src/api.ts
"Merge conflict merging feat/api-v2 into main. Continue with remaining worktrees, or abort? [continue / abort]"

User answers continue (no remaining worktrees) → proceed to cleanup.

# Step 6: Cleanup — only feat/user-auth succeeded
pwd                                    # /repos/myapp ✓
git worktree remove /repos/myapp-auth  # ✓
# /repos/myapp-api NOT removed (status = failed)

Summary:

merge-worktree summary
──────────────────────────────────────────────────────────────────────────
Worktree             Branch          Merge          Push  Cleanup  Branch
/repos/myapp-auth    feat/user-auth  ✓              ✓     ✓        deleted
/repos/myapp-api     feat/api-v2     ✗(conflict)    —     —        —
──────────────────────────────────────────────────────────────────────────

AI Refactor Instruction

If this skill produces incorrect behavior:

  1. Wrong invocation context: if the skill proceeds without verifying CWD matches the main repo → rewind to Step 1, add the invocation guard check
  2. Pre-flight skipped or deferred: if git merge is attempted without first running git -C <path> status --porcelain for all selected worktrees → rewind to Step 4, complete all pre-flight checks before any merge
  3. Failed worktree deleted: if git worktree remove is called for a worktree with status failed → halt; only the <succeeded-list> is eligible for removal
  4. Force-push attempted: if --force or --force-with-lease appears in a push command → substitute standard push; if that fails, halt and report
  5. Pull skipped before merge: if git merge --no-ff runs without a preceding git pull origin <main-branch> → re-run from the pull step

Self-Check

  • Invocation context verified: git rev-parse --show-toplevel matched main repo path before proceeding
  • Main branch confirmed: auto-detected or explicitly provided by user; not assumed
  • All linked worktrees scanned: git worktree list parsed; non-main entries presented to user
  • User selection recorded: all or index-based subset captured before any pre-flight check
  • Pre-flight ran for all selected before any merge: git -C <path> status --porcelain completed for every selected worktree first
  • Dirty worktrees reported upfront: all dirty entries listed together before the continue/halt prompt
  • Pull before each merge: git pull origin <main-branch> ran immediately before each git merge --no-ff
  • No-ff merge used: git merge --no-ff confirmed; no fast-forward or squash
  • Push succeeded before worktree marked succeeded: only after git push returns 0 is a worktree added to <succeeded-list>
  • Unified cleanup ran only on <succeeded-list>: git worktree remove never called for failed or skipped entries
  • CWD confirmed before cleanup: pwd matched <main-repo-path> before any git worktree remove
  • Branch deletion used -d: no -D flag in any branch deletion command; user confirmed each branch
  • Summary report produced: per-worktree table includes all entries with correct status codes
  • No force-push used: --force or --force-with-lease never appeared in any command

平台分布

Codex

35.81%
按下载量换算53

Claude

29.18%
按下载量换算43

Cursor

19.14%
按下载量换算28

Gemini CLI

9.06%
按下载量换算13

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills