gh-stack
Manages stacked PRs and splits multi-part work into reviewable branches with gh-stack. Use for stack creation, viewing, edits, push, submit, sync, rebase, merge, or checkout; when asked to split or isolate work for review; whenever a user mentions a stack, branch layers, dependent PRs, or gh stack; or when a stack is checked out.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- kind
- dev
- name
- gh-stack
- description
- Manages stacked PRs and splits multi-part work into reviewable branches with gh-stack. Use for stack creation, viewing, edits, push, submit, sync, rebase, merge, or checkout; when asked to split or isolate work for review; whenever a user mentions a stack, branch layers, dependent PRs, or gh stack; or when a stack is checked out.
02 资源文件 6
- 参考文档evals/evals.json2.0 KB
- 参考文档evals/fixtures/agents-md.md171 B
- 脚本evals/fixtures/first-layer.sh612 B
- 脚本evals/fixtures/pushed-stack.sh887 B
- 脚本evals/fixtures/stale-trunk.sh696 B
- 许可证references/LICENSE1.0 KB
03 SKILL.md 正文
gh-stack
A stack is a chain of branches, or layers, on a trunk. Each layer has one PR based on the layer
below, so a reviewer reads one layer at a time. gh stack, a GitHub CLI extension, builds stacks
that GitHub groups natively. gh stack <command> --help is authoritative for flags, and the
official guide for the rest. This skill holds what they
leave out: the shape a project needs, how to run gh stack without a terminal, and what GitHub
refuses in a native stack.
Pick the shape
An active playbook decides which work to stack; this section decides how. Read how the project
merges in its AGENTS.md, then take the first case that matches:
- The parts touch the same lines, or cannot land apart: one PR, no stack
- The project merges by pushing a head to its trunk, such as
git push origin <branch>:main: a plain stack, since GitHub refuses to retarget a PR in a native stack, so the push would leave it open. When the project's land steps rungh stack unstackfirst, use a native stack, which Land unstacks before the push - Otherwise: a native stack
Plan the layers before writing code: one concern per layer, foundations at the bottom, each change
in the lowest layer that needs it. A layer you cannot describe in one sentence is two layers. Name
branches <topic>/<concern> unless the project has a convention. A stack is linear, so unrelated
work gets its own PR or stack.
Branch the bottom layer from the remote trunk, since the local trunk can lag, for example when
another worktree holds it: git fetch <remote>, then git switch -c <bottom> <remote>/<trunk>.
Opening PRs needs gh auth status --active --hostname github.com to pass; local layers do not.
When it fails, push the layers with git, open no PR, and say the PRs wait for a signed-in gh.
A stack is consistent when git merge-base --is-ancestor <lower> <upper> succeeds for each pair of
adjacent layers. Run each git rebase --update-refs from <top>, the top layer checked out: git
moves the branch it rebases, but skips without an error every other branch checked out in a
worktree when the rebase starts, the one you started from included. Check that the stack is
consistent before you push, and report a layer that another worktree holds instead of pushing it
stale.
Native stack
Check gh stack --version first; when it fails, run gh extension install github/gh-stack. Once
per clone, run git config rerere.enabled true, which init otherwise asks about under a
terminal. With several remotes, set git config remote.pushDefault <name>.
Under a terminal, gh stack opens prompts or a full-screen view that block an agent forever.
Always run these forms:
| Run | Instead of |
|---|---|
gh stack view --json |
gh stack view |
gh stack init --base <trunk> <branch>..., gh stack add <branch> |
init or add without a branch |
gh stack submit --auto --open |
gh stack submit |
gh stack sync > /dev/null |
gh stack sync, which prompts on a divergence |
gh stack merge <PR or stack-number> --yes |
gh stack merge alone |
gh stack checkout <target>, up, down, top, bottom |
checkout alone, switch, modify |
- Start. Branch the bottom layer as Pick the shape says, then run
gh stack init --base <trunk> <bottom>, which adopts it. Commit, then rungh stack add <next>for each layer above, which branches from the current layer, and commit there. Done whengh stack view --jsonnames<trunk>astrunkand lists the layers bottom to top. Stop here when the user asked for local layers only - Open the PRs. Run
gh stack submit --auto --open;--autowrites the titles, andgh pr edit <number>changes one.submitandsynccan exit 0 after a push or GitHub failed. Done when, aftergit fetch <remote>,git rev-parse <layer> <remote>/<layer>prints one commit twice for each layer,gh pr view <number> --json baseRefName,isDraftshows each PR ready and based on the layer below, and, from two PRs up,gh api 'repos/{owner}/{repo}/stacks?pull_request=<bottom PR>' --jq '.[] | {number, prs: [.pull_requests[].number]}'lists every PR bottom to top; no output means GitHub holds no stack - Change a layer. Check out the layer that owns the change, found with
gh stack view --jsonorgit log --all -- <path>, and commit there. Then rungh stack rebase --upstack, orgh stack rebase --upstack --no-trunkwhen another worktree holds the trunk, asgit worktree listshows, andgh stack push, or follow Force pushes. Done when the stack is consistent from that layer up and step 2's check passes - Sync with the trunk. When another worktree holds the trunk, leave it alone, since
syncandrebasewithout--no-trunkcan fast-forward it there: rungit fetch <remote>, then, from<top>,git rebase --update-refs <remote>/<trunk> <top>, check that the stack is consistent, and rungh stack push. Otherwise rungh stack sync > /dev/null. Done when stderr has noSync aborted,git merge-base --is-ancestor <remote>/<trunk> <bottom>succeeds, and step 2's check passes
To stack open PRs, or a new PR on an open PR in no stack, run
gh stack link --open --base <bottom PR's base> <PR or branch>..., bottom to top; without
--base, link retargets the bottom PR to the default branch.
gh stack link --open <stack-number> <branch> appends a layer to an existing stack. link tracks
nothing locally, so run gh stack checkout <stack-number> before a local gh stack command.
GitHub refuses, in a native stack:
gh pr mergeon any PR: land withgh stack merge- a draft in
gh stack merge: pass--opentosubmitorlink gh pr edit --baseon any PR: rungh stack unstack <stack-number>first, which keeps the PRs and branches, retarget, then relink withgh stack link --open --base <trunk> <PRs bottom to top>when the stack should stay. Once a PR of the stack merged,unstackleaves the stack in place, and step 2'sgh apicheck still prints it
Plain stack
Use git and gh pr only, no gh stack command, so GitHub never groups the PRs.
- Branch each layer from the one below, commit, and push it. Open its PR with
gh pr create --fill --base <layer below>, or--base <trunk>for the bottom one. Done whengh pr view <number> --json baseRefNamenames the layer below for each PR - To change a layer, commit on it, then, from
<top>, rungit rebase --update-refs <layer> <top>, which replays the layers above and moves their branches. When you amended or rebased the layer instead, rungit rebase --update-refs --onto <layer> <its old tip> <top>. To take in the trunk, rungit fetch <remote>andgit rebase --update-refs <remote>/<trunk> <top>. To fold fixes committed on<top>withgit commit --fixup=<commit>into their layers, runtop_before=$(git rev-parse HEAD)after the last fixup, thenGIT_SEQUENCE_EDITOR=: git rebase -i --autosquash --update-refs "$(git merge-base <remote>/<trunk> <bottom>)", and check thatgit diff --exit-code "$top_before" HEADexits 0: a conflict resolved wrong can drop a line while the stack stays consistent. Push each moved branch withgit push --force-with-lease <remote> <branch>..., or follow Force pushes. Done when the stack is consistent
Force pushes
gh stack submit, sync, push, and rebase rewrite or force-push layers, with
--force-with-lease. When a rule says to ask before any force push and a layer is already on the
remote, add commits instead: commit on the owning layer and run git push <remote> <layer>. Then,
for each layer above, bottom to top, run git switch <upper>,
git merge --no-ff --no-edit <layer below>, and git push <remote> <upper>. To take in the trunk,
merge <remote>/<trunk> into the bottom layer the same way, instead of sync or a rebase.
Land
Land the PRs you were asked to land, from the bottom. Done when gh pr view <number> --json state
prints MERGED for each of them and, for each PR merged outside the default branch, you reported
every issue its closing keywords name that is still open, as the last item below says.
When the bottom PR's base is a branch whose own PR merged outside the stack, retarget the bottom PR to the trunk first, in a native stack as the refusals above say.
- The project merges through GitHub: in a native stack,
gh stack merge <PR> --yeswith the project's method flag, such as--squash, lands that PR and every unmerged PR below it, all or nothing unless a merge queue takes them; a stack number lands the whole stack. Pass the method each time, since the last one used is reused otherwise. A plain stack lands with the project's merge command, one PR at a time. After each merge, rungh pr edit <next> --base <trunk>, then, from<top>,git rebase --update-refs --onto <remote>/<trunk> <merged layer's old tip> <top>, and push the moved branches - The project merges by pushing a head to its trunk: in a native stack, first run
gh stack unstack <stack-number>. Then retarget every PR to the trunk, bottom to top, withgh pr edit <number> --base <trunk>, push every layer you rebased, and apply the project's method once to the top layer. A PR turnsMERGEDwhen its head on GitHub reaches its base. When the stack remains after the unstack, apply the method, then, for each PR still open, bottom to top, rungit push <remote> <layer>:refs/heads/<layer below>, a fast-forward that marks it merged into the layer below. GitHub ignores the closing keywords of a PR whose base is not the default branch, so list the issues each such PR body names with a closing keyword, as#Nin the PR's repository orowner/repo#N, check each withgh issue view <N> -R <owner/repo> --json state, and report every one still open with its PR
Recovery
- Exit 3, a rebase conflict: after
gh stack rebase, resolve the files, rungit add, thengh stack rebase --continue, or--abortto restore every layer. Aftergh stack sync, the stack is already restored: rungh stack rebaseto replay the conflict - Exit 9: stacked PRs are off for the repository; use a plain stack
Sync aborted, the local and GitHub stacks diverged: keep GitHub's withgh stack unstack --localandgh stack checkout <stack-number>, or rebuild from the local branches as the next item says- Rebuild from local branches, or reorder or drop a layer: rewrite the branches with git, run
gh stack unstack, which also drops local tracking, thengh stack init --base <trunk> <branches bottom to top>, which adopts them, andgh stack submit --auto --open - Another exit code: read stderr, then the CLI reference
04 同仓库更多 Skills
writing-great-skills
Use when creating, modifying, evaluating a skill.
writing-for-agents
Use when creating, editing, or reviewing a skill, AGENTS.md, CLAUDE.md, or another document agents read.
why
Use for questions about design rationale, the history of regressions or incidents, or the evidence behind thresholds and tradeoffs. Use `how` for runtime behavior. Do not use for plain commit or date lookups.
verify-video-archive
Use when validating the macOS or Linux archive workflow reached by `just convert-video`, including real media, prerequisites, terminal progress, source safety, locking, and recovery.
verify-transcript
Use when validating transcript CLI behavior, locating its verification features, or running the paid YouTube end-to-end check.
verify-skills
Use when verifying `just compile-skills`, `just remote-skills`, `just install-skills`, or `just skills-discover` in the skills repository, such as after changing their scripts or adding, renaming, or moving a skill.