inherit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

inherit

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
/ship
(outbound to a target) and
/isolate
(forks a new child from a parent).
思维模型:「我是子分支,我想要父分支的所有内容。」
将当前分支(可选包含其下游分支)更新至与父分支同步状态。是/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-trim
    ,
    gh
    aren't available.
Do NOT use to send changes upward — that's
/ship
. Do NOT use to create a new branch — that's
/isolate
.
  • 当前分支相对于基准分支已过期
  • 一系列依赖分支需要将父分支的最新提交级联同步
  • Web会话或极简环境中无法使用
    wt
    git-trim
    gh
    工具
请勿用于向上推送变更——那是/ship的用途。请勿用于新建分支——那是/isolate的用途。

Why merge, not rebase

为什么用merge而非rebase

Autonomous mode's
git-rewrite-guard.sh
blocks
git rebase
,
--amend
,
reset --hard
, and
push --force*
. 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
git merge
, never
git rebase
in this skill.
自主模式下的
git-rewrite-guard.sh
会阻止
git rebase
--amend
reset --hard
push --force*
操作。Merge也是并行工作区社区中基准同步的标准方式——非破坏性、支持栈式分支、无需强制推送、在共享检出环境下安全。在此技能中始终使用
git merge
,绝不使用
git rebase

Constraints

约束条件

  • Pure git only. No
    wt
    ,
    git-trim
    , or
    gh
    for the merge step. Works in web sandboxes.
  • Always
    git -C <abs-path>
    for state-mutating ops.
    cd
    does not persist between Claude Code Bash calls; bare
    git
    from session CWD hits the primary worktree.
  • Never auto-resolve conflicts. The user owns conflict resolution.
  • 仅使用原生git命令。合并步骤不使用
    wt
    git-trim
    gh
    工具,可在Web沙箱中运行。
  • 执行状态变更操作时始终使用
    git -C <abs-path>
    cd
    命令在Claude Code Bash调用间无法保持状态;直接使用
    git
    会基于会话当前工作目录操作主工作区。
  • 绝不自动解决冲突。冲突解决由用户负责。

Inputs

输入参数

FlagPurpose
--stack
Cascade the merge bottom-up through dependent branches
--parent <name>
Override auto-detected parent
--no-push
Skip the push step (commits stay local)
CI-down signal: same convention as
/ship
— if user has signaled CI is down, substitute
/local-merge
for each
git push
.
标记用途
--stack
自底向上将合并操作级联到所有依赖分支
--parent <name>
覆盖自动检测到的父分支
--no-push
跳过推送步骤(提交仅保留在本地)
CI禁用信号:与/ship遵循相同约定——若用户告知CI已禁用,则将每个
git push
替换为
/local-merge

Procedure

操作流程

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:
  • CURRENT
    is
    HEAD
    (detached) → "No current branch — checkout a branch first."
  • Working tree dirty (
    git -C "$REPO" status --porcelain
    non-empty) → "Commit or stash local changes before inheriting."
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)

2. 检测父分支(若未传入
--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}"
  • grep -m1
    picks the most recent "Created from" — that's the actual fork point.
  • Strip leading
    origin/
    so we work in branch-name space.
  • Fall back to
    main
    when reflog is empty (web sessions, fresh clones, branches created via fetch). Tell the user it was a fallback so they can correct via
    --parent
    .
  • If
    PARENT == CURRENT
    after resolution → "Already on parent branch; nothing to inherit."
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}"
  • grep -m1
    选取最近的「Created from」记录——即实际分叉点。
  • 移除前缀
    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
    git status
    , list conflicted paths, hand control back. Do NOT attempt automatic resolution.
bash
git -C "$REPO" merge --no-edit "origin/$PARENT"
结果:
  • 无冲突(正常合并或快进合并) → 继续执行。
  • 无操作(已同步) → 直接告知用户并跳过推送步骤。
  • 冲突 → 终止操作,显示
    git status
    ,列出冲突路径,交回控制权。绝不尝试自动解决冲突。

5. Cascade through stack (only if
--stack
)

5. 级联到分支栈(仅当使用
--stack
时)

A "dependent" is a local branch with
CURRENT
as an ancestor. The user supplies the candidate set after
--stack
(or names them inline); don't guess silently — if the user didn't name them, ask once.
Order: bottom-up, parent-first. Use pairwise
git merge-base --is-ancestor
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:
bash
undefined
「依赖分支」指以
CURRENT
为祖先的本地分支。用户需在
--stack
后提供候选分支集合(或直接内联命名);请勿静默猜测——若用户未指定分支名称,需询问一次。
顺序:自底向上,先父分支后子分支。使用成对的
git merge-base --is-ancestor
确定拓扑顺序——每一步从剩余分支中选取一个没有其他剩余分支作为其祖先的分支,该分支即为下一个处理对象:
bash
undefined

B 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)

6. 推送(若CI禁用则使用
/local-merge

For each branch that received commits (
CURRENT
plus any cascaded children):
bash
git -C "$REPO" push origin "$BRANCH"
If user has signaled CI is down: invoke
/local-merge
per branch instead. If
--no-push
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
/inherit
.
对每个接收了提交的分支(
CURRENT
及所有级联子分支):
bash
git -C "$REPO" push origin "$BRANCH"
若用户告知CI已禁用:对每个分支调用
/local-merge
替代推送。 若传入
--no-push
:完全跳过推送步骤;告知用户分支已存在本地合并提交,等待发布。 若推送被拒绝(远端已更新):绝不强制推送。报告拒绝信息;由用户决定是否重新运行
/inherit

7. 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

快速参考

StepCommand
Detect parent
git reflog show HEAD --pretty=format:'%gs' | grep -m1 '^branch: Created from'
Fetch
git -C "$REPO" fetch origin "$PARENT"
Merge in
git -C "$REPO" merge --no-edit "origin/$PARENT"
Stack order
git merge-base --is-ancestor <a> <b>
pairwise, root-first
Push
git -C "$REPO" push origin <branch>
CI down
/local-merge
per branch
步骤命令
检测父分支
git reflog show HEAD --pretty=format:'%gs' | grep -m1 '^branch: Created from'
拉取
git -C "$REPO" fetch origin "$PARENT"
合并
git -C "$REPO" merge --no-edit "origin/$PARENT"
分支栈顺序成对使用
git merge-base --is-ancestor <a> <b>
,从根分支开始
推送
git -C "$REPO" push origin <branch>
CI禁用对每个分支使用
/local-merge

Failure modes — explicit counters

错误模式——明确禁止

RationalizationCounter
"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
main
. Tell the user. Do not infer from naming.
"I'll force-push after a tidy rebase"Forbidden. No
--force
,
--force-with-lease
, or
--amend
in this skill.
"I'll use
git pull --rebase
"
Same prohibition as
git rebase
. Use plain
git merge
.
"I'll use
wt sync
/
git-trim
"
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
--no-push
applies.
"Conflict? I'll auto-resolve with
-X theirs
"
Never. The user owns conflict resolution. Stop and report.
错误理由禁止依据
「Rebase更整洁——我要rebase到main分支」禁止。自主模式下的rewrite-guard会阻止该操作。请使用merge。
「引用日志为空,我要根据分支名称模式猜测」回退使用
main
。告知用户。请勿根据命名推断。
「我要在整理rebase后强制推送」禁止。在此技能中不得使用
--force
--force-with-lease
--amend
「我要使用
git pull --rebase
git rebase
同样被禁止。请使用原生
git merge
「我要使用
wt sync
/
git-trim
仅使用原生git命令——这些工具在Web会话中不可用。
「分支栈顺序无关紧要,我可以任意顺序合并」需自底向上合并(先处理靠近根分支的分支),确保每个子分支能获取到更新后的父分支。
「我要跳过推送步骤」除非CI禁用或使用
--no-push
,否则需推送每个更新后的分支。
「有冲突?我要用
-X theirs
自动解决」
绝不允许。冲突解决由用户负责。请终止操作并报告。

Red flags — STOP

警示信号——立即停止

  • About to type
    git rebase
    ,
    --amend
    ,
    reset --hard
    , or
    --force
    → wrong skill.
  • 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
    git
    without
    -C
    from session CWD on a non-primary worktree.
  • Modifying files outside git operations — this skill is pure git.
  • 即将输入
    git rebase
    --amend
    reset --hard
    --force
    → 使用了错误的技能。
  • 父分支检测返回空值且未回退使用
    main
  • 自顶向下合并分支栈(最后处理父分支)→ 反转顺序。
  • 在非主工作区中,未使用
    -C
    参数直接从会话当前工作目录执行
    git
    命令。
  • 在git操作外修改文件——此技能仅使用原生git命令。

Companion skills

配套技能

  • /isolate
    — forks a new child off a parent.
  • /inherit
    (this skill) — pulls parent → child. Inbound.
  • /ship
    — pushes child → target. Outbound.
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