skills/merge-stack/SKILL.md
Merge a linear stack of GitHub PRs into main one by one. Use when the user has multiple PRs that form a chain and wants to merge them sequentially. Triggers on phrases like "merge the stack", "merge my PRs", or "merge stacked PRs".
npx skillsauth add rarestg/rarestg-skills merge-stackInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Merge a linear chain of stacked PRs into main one at a time, re-targeting
each subsequent PR to main before merging.
gh pr list --state open \
--json number,title,headRefName,baseRefName,additions,deletions \
--jq '.[] | "#\(.number) \(.headRefName) → \(.baseRefName) (+\(.additions) -\(.deletions))"'
If a branch prefix argument is provided, filter to only PRs whose branch names
match it. Confirm the PRs form a single linear chain ending at main. Show the
user the full stack, bottom to top, and get confirmation before proceeding.
Starting with the PR that targets main:
Merge it: gh pr merge <number> --merge
For each next PR in the chain:
a. Inspect its current base. If GitHub already re-targeted it to main,
continue. Otherwise, re-target it to main with the REST API:
repo=$(gh repo view --json nameWithOwner --jq .nameWithOwner)
gh api -X PATCH "repos/${repo}/pulls/<number>" -f base=main \
--jq '"#\(.number) \(.head.ref) → \(.base.ref)"'
If GH_HOST is set to a host that is not the PR host, unset or correct
it for both commands. For a GitHub.com PR from an environment with a stale
enterprise/internal GH_HOST, use:
repo=$(env -u GH_HOST gh repo view --json nameWithOwner --jq .nameWithOwner)
env -u GH_HOST gh api -X PATCH "repos/${repo}/pulls/<number>" -f base=main \
--jq '"#\(.number) \(.head.ref) → \(.base.ref)"'
b. Merge it: gh pr merge <number> --merge
Repeat until all PRs are merged.
Use --merge, not --squash or --rebase, to preserve commit history unless
the user requests otherwise.
Do not pass --delete-branch to gh pr merge for stacked PRs. If the repo is
configured to delete merged branches, let GitHub do that server-side. A local
CLI-driven branch deletion can remove the base branch before GitHub re-targets
dependent PRs, causing the next PR in the stack to close instead of retargeting
to main.
Prefer the REST retarget command above instead of
gh pr edit <number> --base main. GitHub CLI 2.45.0 can route gh pr edit
through a broader GraphQL path that queries repository.pullRequest.projectCards
even when no project flag is used. That can fail because Projects Classic fields
are deprecated. The REST "Update a pull request" endpoint accepts base
directly and changes exactly the field this workflow needs.
If REST retargeting fails, stop and report the GitHub error. Do not fall back
to gh pr edit; permission, validation, and base-branch errors should be fixed
directly. Fine-grained tokens need pull-request write access.
Changing a PR base can make commits disappear from the PR timeline and mark
review comments outdated. This workflow still does it intentionally because each
PR is merged into main first, then the next PR must target the newly updated
base. Retargeting does not update or merge main into the PR head branch.
References:
gh pr list --state open
Confirm zero open PRs remain (or only unrelated PRs remain) and report the result.
main, suggest gh pr merge <number> --merge --auto to
auto-merge once checks pass.feature-1,
feature-2, but detect the actual chain by following base branch references,
not by name pattern.tools
Break large code changes into small, stacked pull requests using vanilla git and the gh CLI. Auto-trigger when implementing a feature or change that spans multiple logical steps, touches several files, or will exceed ~200 changed lines. Also trigger on "stack PRs", "break this into smaller PRs", "stacked diffs", or "create a PR stack". Do NOT trigger for single-file fixes, small bug fixes, or changes under ~200 lines that are a single logical unit.
development
Export a PR's clean inline review comments, CodeRabbit outside-diff comments, and CodeRabbit nitpicks into local files, then triage review feedback through a stack-aware orchestrator workflow with durable reply drafts for follow-up PRs. Use when given a GitHub pull request URL and asked to work through review comments without relying on noisy raw API blobs.
development
Run reusable Graphify-led architecture analysis for codebases using semantic graphs, optional subagent extraction, graph synthesis, source-search validation, graph-shape review, and follow-up refactor planning. Use when asked to analyze repo architecture, god nodes, surprising edges, topology, module boundaries, or graph-derived cleanup/refactor opportunities.
testing
Run a meaningful coding ticket through a delegated delivery workflow: tighten the ticket, assign one ticket owner, delegate implementation, get an independent review, scan for high-value simplification, validate the result, and return a compact outcome packet. Use when the user wants structured agent execution with clear scope, ownership, and review rather than a single-pass implementation. Triggers on: "delegate this ticket", "use a sub-PM", "run this through worker and reviewer", "own this ticket end to end", "send this for independent review", or "close this ticket out with review". Skip trivial fixes and tasks that are still too vague to delegate.