inherit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseinherit
inherit
Mental model: "I am the child. I want what my parent has."
Brings the current branch (and optionally its descendants) up to date with its parent. Inbound counterpart to (outbound to a target) and (forks a new child from a parent).
/ship/isolate思维模型:「我是子分支,我想要父分支的所有内容。」
将当前分支(可选包含其下游分支)更新至与父分支同步状态。是/ship(推送到目标分支,向外操作)和/isolate(从父分支新建子分支)的对应向内操作。
When to use
使用场景
- Current branch is stale relative to its base.
- A stack of dependent branches needs the parent's latest commits cascaded down.
- Web sessions or minimal environments where ,
wt,git-trimaren't available.gh
Do NOT use to send changes upward — that's . Do NOT use to create a new branch — that's .
/ship/isolate- 当前分支相对于基准分支已过期
- 一系列依赖分支需要将父分支的最新提交级联同步
- Web会话或极简环境中无法使用、
wt、git-trim工具gh
请勿用于向上推送变更——那是/ship的用途。请勿用于新建分支——那是/isolate的用途。
Why merge, not rebase
为什么用merge而非rebase
Autonomous mode's blocks , , , and . Merge is also the parallel-worktree community standard for syncing from base — non-destructive, composes with stacks, never requires a force-push, safe under shared checkouts. Always , never in this skill.
git-rewrite-guard.shgit rebase--amendreset --hardpush --force*git mergegit rebase自主模式下的会阻止、、和操作。Merge也是并行工作区社区中基准同步的标准方式——非破坏性、支持栈式分支、无需强制推送、在共享检出环境下安全。在此技能中始终使用,绝不使用。
git-rewrite-guard.shgit rebase--amendreset --hardpush --force*git mergegit rebaseConstraints
约束条件
- Pure git only. No ,
wt, orgit-trimfor the merge step. Works in web sandboxes.gh - Always for state-mutating ops.
git -C <abs-path>does not persist between Claude Code Bash calls; barecdfrom session CWD hits the primary worktree.git - Never auto-resolve conflicts. The user owns conflict resolution.
- 仅使用原生git命令。合并步骤不使用、
wt或git-trim工具,可在Web沙箱中运行。gh - 执行状态变更操作时始终使用。
git -C <abs-path>命令在Claude Code Bash调用间无法保持状态;直接使用cd会基于会话当前工作目录操作主工作区。git - 绝不自动解决冲突。冲突解决由用户负责。
Inputs
输入参数
| Flag | Purpose |
|---|---|
| Cascade the merge bottom-up through dependent branches |
| Override auto-detected parent |
| Skip the push step (commits stay local) |
CI-down signal: same convention as — if user has signaled CI is down, substitute for each .
/ship/local-mergegit push| 标记 | 用途 |
|---|---|
| 自底向上将合并操作级联到所有依赖分支 |
| 覆盖自动检测到的父分支 |
| 跳过推送步骤(提交仅保留在本地) |
CI禁用信号:与/ship遵循相同约定——若用户告知CI已禁用,则将每个替换为。
git push/local-mergeProcedure
操作流程
1. Resolve current branch + repo root
1. 确定当前分支和仓库根目录
bash
REPO="$(git rev-parse --show-toplevel)"
CURRENT="$(git -C "$REPO" rev-parse --abbrev-ref HEAD)"Pre-flight aborts:
- is
CURRENT(detached) → "No current branch — checkout a branch first."HEAD - Working tree dirty (non-empty) → "Commit or stash local changes before inheriting."
git -C "$REPO" status --porcelain
bash
REPO="$(git rev-parse --show-toplevel)"
CURRENT="$(git -C "$REPO" rev-parse --abbrev-ref HEAD)"预检终止条件:
- 为
CURRENT(分离头指针状态)→ 「无当前分支——请先检出一个分支。」HEAD - 工作区未提交变更(输出非空)→ 「继承前请提交或暂存本地变更。」
git -C "$REPO" status --porcelain
2. Detect parent (unless --parent
was passed)
--parent2. 检测父分支(若未传入--parent
)
--parentbash
PARENT=$(git -C "$REPO" reflog show HEAD --pretty=format:'%gs' \
| grep -m1 '^branch: Created from ' \
| sed -E 's/^branch: Created from //; s|^origin/||')
PARENT="${PARENT:-main}"- picks the most recent "Created from" — that's the actual fork point.
grep -m1 - Strip leading so we work in branch-name space.
origin/ - Fall back to when reflog is empty (web sessions, fresh clones, branches created via fetch). Tell the user it was a fallback so they can correct via
main.--parent - If after resolution → "Already on parent branch; nothing to inherit."
PARENT == CURRENT
Echo before mutating:
Detected parent: <PARENT> (current: <CURRENT>). Inheriting from origin/<PARENT>.bash
PARENT=$(git -C "$REPO" reflog show HEAD --pretty=format:'%gs' \
| grep -m1 '^branch: Created from ' \
| sed -E 's/^branch: Created from //; s|^origin/||')
PARENT="${PARENT:-main}"- 选取最近的「Created from」记录——即实际分叉点。
grep -m1 - 移除前缀,以分支名称进行操作。
origin/ - 若引用日志为空(Web会话、新克隆仓库、通过fetch创建的分支),则回退使用。告知用户这是回退方案,可通过
main修正。--parent - 若解析后→ 「已处于父分支;无需继承。」
PARENT == CURRENT
执行变更前输出:
检测到父分支: <PARENT> (当前分支: <CURRENT>). 从origin/<PARENT>继承变更。3. Fetch the parent
3. 拉取父分支
bash
git -C "$REPO" fetch origin "$PARENT"If fetch fails (offline, ref missing, parent deleted on origin): surface the error verbatim. Do NOT silently substitute another branch.
bash
git -C "$REPO" fetch origin "$PARENT"若拉取失败(离线、引用不存在、父分支已在远端删除):直接显示错误信息。请勿静默替换为其他分支。
4. Merge parent into current
4. 将父分支合并到当前分支
bash
git -C "$REPO" merge --no-edit "origin/$PARENT"Outcomes:
- Clean (real merge or fast-forward) → proceed.
- No-op (already up to date) → say so plainly and skip the push.
- Conflict → stop, show , list conflicted paths, hand control back. Do NOT attempt automatic resolution.
git status
bash
git -C "$REPO" merge --no-edit "origin/$PARENT"结果:
- 无冲突(正常合并或快进合并) → 继续执行。
- 无操作(已同步) → 直接告知用户并跳过推送步骤。
- 冲突 → 终止操作,显示,列出冲突路径,交回控制权。绝不尝试自动解决冲突。
git status
5. Cascade through stack (only if --stack
)
--stack5. 级联到分支栈(仅当使用--stack
时)
--stackA "dependent" is a local branch with as an ancestor. The user supplies the candidate set after (or names them inline); don't guess silently — if the user didn't name them, ask once.
CURRENT--stackOrder: bottom-up, parent-first. Use pairwise to find topological order — at each step, pick a branch in the remaining set that no other remaining branch is an ancestor of. That branch goes next:
git merge-base --is-ancestorbash
undefined「依赖分支」指以为祖先的本地分支。用户需在后提供候选分支集合(或直接内联命名);请勿静默猜测——若用户未指定分支名称,需询问一次。
CURRENT--stack顺序:自底向上,先父分支后子分支。使用成对的确定拓扑顺序——每一步从剩余分支中选取一个没有其他剩余分支作为其祖先的分支,该分支即为下一个处理对象:
git merge-base --is-ancestorbash
undefinedB is downstream of A iff A is an ancestor of B
若A是B的祖先,则B是A的下游分支
git -C "$REPO" merge-base --is-ancestor "$A" "$B" # exit 0 = yes
For each branch in that order, merge its **direct parent in the chain** (the previous branch processed) — NOT `origin/main` again. The whole point of cascading is that the parent already absorbed main, and now the child absorbs the updated parent:
```bash
PREV="$CURRENT"
for child in "${ordered[@]}"; do
git -C "$REPO" checkout "$child"
git -C "$REPO" merge --no-edit "$PREV" # stop on conflict
PREV="$child"
done
git -C "$REPO" checkout "$CURRENT"On conflict: stop the cascade. Report which branch wedged and which paths conflict. Do NOT skip forward.
git -C "$REPO" merge-base --is-ancestor "$A" "$B" # 返回0表示是
对每个按顺序处理的分支,合并其**链中的直接父分支**(上一个处理的分支)——而非再次合并`origin/main`。级联的核心意义在于父分支已同步了main分支的变更,现在子分支只需同步更新后的父分支:
```bash
PREV="$CURRENT"
for child in "${ordered[@]}"; do
git -C "$REPO" checkout "$child"
git -C "$REPO" merge --no-edit "$PREV" # 遇到冲突则终止
PREV="$child"
done
git -C "$REPO" checkout "$CURRENT"若遇到冲突:终止级联操作。报告哪个分支出现问题以及冲突路径。绝不跳过继续执行。
6. Push (or /local-merge
if CI is down)
/local-merge6. 推送(若CI禁用则使用/local-merge
)
/local-mergeFor each branch that received commits ( plus any cascaded children):
CURRENTbash
git -C "$REPO" push origin "$BRANCH"If user has signaled CI is down: invoke per branch instead.
If was passed: skip entirely; tell the user the branch(es) have local merge commits awaiting publish.
If push is rejected (remote moved): do NOT force. Report the rejection; the user decides whether to re-run .
/local-merge--no-push/inherit对每个接收了提交的分支(及所有级联子分支):
CURRENTbash
git -C "$REPO" push origin "$BRANCH"若用户告知CI已禁用:对每个分支调用替代推送。
若传入:完全跳过推送步骤;告知用户分支已存在本地合并提交,等待发布。
若推送被拒绝(远端已更新):绝不强制推送。报告拒绝信息;由用户决定是否重新运行。
/local-merge--no-push/inherit7. Report
7. 结果报告
Concise summary, not paragraphs:
Inherited from <PARENT> into:
- <CURRENT> (merge <sha>, pushed)
- <child-1> (merge <sha>, pushed)On conflict:
Inherit halted on <branch>: conflicts in <files>. Resolve, commit, then re-run /inherit.简洁总结,无需长篇大论:
已从<PARENT>继承变更到:
- <CURRENT> (合并提交<sha>,已推送)
- <child-1> (合并提交<sha>,已推送)若遇到冲突:
继承操作在<branch>分支终止:<files>存在冲突。请解决冲突并提交后,重新运行/inherit。Quick reference
快速参考
| Step | Command |
|---|---|
| Detect parent | |
| Fetch | |
| Merge in | |
| Stack order | |
| Push | |
| CI down | |
| 步骤 | 命令 |
|---|---|
| 检测父分支 | |
| 拉取 | |
| 合并 | |
| 分支栈顺序 | 成对使用 |
| 推送 | |
| CI禁用 | 对每个分支使用 |
Failure modes — explicit counters
错误模式——明确禁止
| Rationalization | Counter |
|---|---|
| "Rebase is cleaner — I'll just rebase onto main" | Forbidden. Rewrite-guard blocks it in autonomous mode. Use merge. |
| "Reflog is empty, I'll guess from branch-name patterns" | Fall back to |
| "I'll force-push after a tidy rebase" | Forbidden. No |
"I'll use | Same prohibition as |
"I'll use | Pure git only — those binaries aren't in web sessions. |
| "Stack order doesn't matter, I'll merge in any order" | Merge bottom-up (root-adjacent first) so each child sees its updated parent. |
| "I'll skip the push" | Push each updated branch unless CI-down or |
"Conflict? I'll auto-resolve with | Never. The user owns conflict resolution. Stop and report. |
| 错误理由 | 禁止依据 |
|---|---|
| 「Rebase更整洁——我要rebase到main分支」 | 禁止。自主模式下的rewrite-guard会阻止该操作。请使用merge。 |
| 「引用日志为空,我要根据分支名称模式猜测」 | 回退使用 |
| 「我要在整理rebase后强制推送」 | 禁止。在此技能中不得使用 |
「我要使用 | 与 |
「我要使用 | 仅使用原生git命令——这些工具在Web会话中不可用。 |
| 「分支栈顺序无关紧要,我可以任意顺序合并」 | 需自底向上合并(先处理靠近根分支的分支),确保每个子分支能获取到更新后的父分支。 |
| 「我要跳过推送步骤」 | 除非CI禁用或使用 |
「有冲突?我要用 | 绝不允许。冲突解决由用户负责。请终止操作并报告。 |
Red flags — STOP
警示信号——立即停止
- About to type ,
git rebase,--amend, orreset --hard→ wrong skill.--force - Parent detection silently returned empty and you didn't fall back to .
main - Merging top-down through a stack (parent-most last) → reverse the order.
- Bare without
gitfrom session CWD on a non-primary worktree.-C - Modifying files outside git operations — this skill is pure git.
- 即将输入、
git rebase、--amend或reset --hard→ 使用了错误的技能。--force - 父分支检测返回空值且未回退使用。
main - 自顶向下合并分支栈(最后处理父分支)→ 反转顺序。
- 在非主工作区中,未使用参数直接从会话当前工作目录执行
-C命令。git - 在git操作外修改文件——此技能仅使用原生git命令。
Companion skills
配套技能
- — forks a new child off a parent.
/isolate - (this skill) — pulls parent → child. Inbound.
/inherit - — pushes child → target. Outbound.
/ship
Three directions a branch moves: fork off, sync down, ship up.
- —— 从父分支分叉新建子分支。
/isolate - (本技能)—— 从父分支拉取变更到子分支。向内操作。
/inherit - —— 将子分支变更推送到目标分支。向外操作。
/ship
分支的三种移动方向:分叉、同步、推送。
Example invocations
调用示例
- "pull main into this branch" →
/inherit - "update my stack from main" →
/inherit --stack - "sync from base but don't push yet" →
/inherit --no-push - "catch up to develop instead of main" →
/inherit --parent develop
- "pull main into this branch" →
/inherit - "update my stack from main" →
/inherit --stack - "sync from base but don't push yet" →
/inherit --no-push - "catch up to develop instead of main" →
/inherit --parent develop