agentleFS
s3s-projects3s-project/s3s/.agents/skills/gh-stack/SKILL.md

gh-stack

Skill313 starsChanged 26 days agoApache-2.0View on GitHub

Work with stacked pull requests in this repository using gh stack. Use when a change is split across branches that build on each other, when a stack must be rebased, synced, pushed or merged, or when a force-push to a stack branch has to be safe.

  • Deletes or force-pushes

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 41 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before any push, compare the three heads:

    line 59
  2. Very specific:

    After the last layer merges, delete the head branches (remote and local) and remove the worktree.

    line 76

“Common” is measured: kept by at least 6 in 10 of the 41 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Stacked pull requests

A stack is a chain of branches where each layer is based on the one below it, main ← layer-1 ← layer-2, and each layer is its own pull request. This repository enables GitHub's stacked pull requests, and the gh stack command manages them: it keeps the local branches, the remote branches, the pull requests and the GitHub stack object in step.

gh stack is an extension, not a core gh command, so install it once and confirm it is there:

gh extension install github/gh-stack
gh extension list

Reach for a stack when a change is genuinely layered: one logical change per layer, each one reviewable on its own, with the lower layers merging first. Read the pull-request skill for the commit series, title and body of each layer; this skill covers the stack around them.

The local map

gh stack init layer-1 layer-2      # adopt existing branches bottom to top, or create missing ones
gh stack view                      # stack number, layers, PR links, current branch
gh stack switch                    # move between layers
gh stack checkout <branch|PR|URL>  # jump to a stack by number, PR, URL or branch
gh stack add layer-3               # branch on top of the current top, then commit
gh stack modify                    # restructure interactively

init adopts existing branches without rewriting them: the branch names and commits stay, only the relationship is recorded. When a layer changes, the layers above it need a rebase (below).

Publishing

gh stack submit --auto --remote <name>   # push every layer, open the missing PRs
gh stack push --remote <name>            # push the branches only
gh stack rebase                          # fetch and cascade-rebase locally, no push
gh stack sync                            # fetch, reconcile, rebase, push atomically, re-link the stack
  • submit without --auto opens an editor; with --auto it skips it. --auto creates new pull requests as drafts and --open marks them ready. The main ruleset runs Copilot review on drafts too (review_draft_pull_requests: true, review_on_push: false), so a draft gets a review but an amend does not trigger a second one.
  • An --auto title is not always the commit subject: a layer whose branch name is not a Conventional Commit subject gets a title built from the branch name. Check every layer (gh pr view <n> --json title,isDraft,baseRefName) and correct it with gh pr edit before asking for review.
  • sync is the safe way to reconcile: it pulls down branches that were added to the stack on GitHub, fast-forwards the trunk, cascade-rebases and pushes atomically. It prompts when local and remote diverge, which is the moment to stop and look rather than push.

When the remote cannot be chosen

A checkout can carry more than one remote, and gh stack then refuses to pick one: multiple remotes configured; set remote.pushDefault or use an interactive terminal. Name the remote where the command takes one — gh stack submit --remote <name>, gh stack push --remote <name> — and for rebase and sync, which have no such flag, inject the setting for that single command rather than changing the repository configuration:

GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=remote.pushDefault GIT_CONFIG_VALUE_0=<name> gh stack rebase

Never overwrite a rebase you did not make

gh stack push force-pushes each layer with --force-with-lease computed from the stack's own view, so it can replace work that moved the branch elsewhere — including the GitHub Rebase stack button, which rebases on the server and force-pushes both layers. The lease does not save you, because the stack refreshes what it considers the expected remote state.

Before any push, compare the three heads:

git fetch <remote>
git rev-parse --short HEAD <remote>/<branch>
gh pr view <n> --json headRefOid --jq .headRefOid

When the remote head is not what you last pushed, stop and reconcile (gh stack sync, or a plain git reset --hard <remote>/<branch> when you simply want to adopt the remote) instead of pushing over it. Keep a backup ref before any rewrite: git branch backup/<what> <sha>. And run gh stack from one worktree at a time: two sessions inside one stack each see a different "local" state.

Landing

main takes pull requests through a merge queue with the squash method (minimum one entry, a ten-minute wait, all green). The ruleset requires only the status-check context, does not require branches to be up to date (strict_required_status_checks_policy: false), and requires linear history, so a stack does not have to be rebased onto the newest main to be mergeable.

  • Merge from the bottom. When layer 1 lands, GitHub retargets layer 2's base to main; merge it next. gh stack merge merges the layers in order.
  • The GitHub UI offers Rebase stack and Enqueue stack; the CLI equivalents are gh stack rebase followed by gh stack push, and enqueueing the bottom pull request.
  • CI runs on pull_request and again on merge_group: the queue re-runs the required checks, so read the merge_group run before treating a queue failure as a code failure.
  • After the last layer merges, delete the head branches (remote and local) and remove the worktree. A fully merged stack needs no gh stack unstack; that command is for abandoning or restructuring a stack whose layers will not merge in order.

Watching a stack

gh stack view                                  # the map and the PR links
gh pr checks <n>                               # one layer at a time; the stack has no single check set
cargo run -p xtask -- watch-pr <n>             # the state that decides landing, with a restorable baseline
gh pr view <n> --json state,mergeStateStatus,mergedAt

Where to look

Download now (ZIP)

  • Other versions42 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 42

    1. vercel/next.js★ 143ksame name
    2. remotion-dev/remotion★ 70ksame name
    3. CherryHQ/cherry-studio★ 53ksame name
    4. Arize-ai/phoenix★ 12ksame name
    5. trycompai/crm★ 11ksame name
    6. CherryHQ/cherry-studio-app★ 4ksame name
    7. dotnet/macios★ 2.9ksame name
    8. dotnet/android★ 2.1ksame name
    9. github/gh-stack★ 1.7ksame name
    10. NVIDIA-NeMo/Gym★ 1.2ksame name

    32 more not listed

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • Used alongsideProjects with it also use gh-create-pr, gh-commit and 10 more.

    Other files people use alongside this one.

    Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
    • ant-designSkill

      gh-create-pr

      使用 GitHub CLI (gh) 推送当前分支并创建或更新 PR。在用户说「提 PR」「新建 PR」「用 gh 建 PR」「submit PR」「create pull request」时使用。

      Also in 4 projects that use this

    • kelvincushmanSkill

      gh-commit

      Create well-formatted commits with conventional commit format.

      Also in 3 projects that use this

    • bmsuisseSkill

      prek

      Set up code formatting and pre-commit hooks using prek (fast Rust-based alternative to pre-commit) with prek.toml config. Use whenever the user wants to configure prek, add formatters, set up pre-commit hooks, or enforce code style. Triggers on "set up prek", "add formatting", "configure formatters", "pre-commit setup", "add ruff", "set up biome", "configure sqlfmt". Works on new and existing projects. Always use when init-app-stack has just run.

      Also in 3 projects that use this

    • carapace-shSkill

      bun

      Use when working with the bun CLI — Bun's all-in-one JavaScript runtime and toolkit. Covers the CLI command reference (install, add, remove, run, build, test, x, create, init, pm, upgrade, link, unlink), bunfig.toml configuration, environment variables, the package manager and lockfile, the test runner, the bundler, the Bun runtime API (Bun.serve, Bun.file, Bun.spawn, Bun.write, hashing, transpiler), the Bun shell ($ template literal), module resolution and loaders, and globals. Triggers on: "bun", "bunx", "bun install", "bun add", "bun remove", "bun run", "bun build", "bun test", "bun x", "bun create", "bun init", "bun pm", "bun upgrade", "bun link", "bun unlink", "bunfig.toml", "bun.lock", "Bun.serve", "Bun.file", "Bun.write", "Bun.spawn", "Bun.hash", "Bun.password", "bun:test", "Bun.build", "Bun.Transpiler", "bun shell", "$ template", "import.meta", "JavaScriptCore", "Bun.serve", "HTMLRewriter", "Bun.SQL", "Bun.RedisClient", "Bun.Glob", "Bun.plugin", "bun:ffi".

      Also in 3 projects that use this

    • xfstudioSkill

      typescript-expert

      TypeScript and JavaScript expert with deep knowledge of type-level programming, performance optimization, monorepo management, migration strategies, and modern tooling. Use PROACTIVELY for any TypeScript/JavaScript issues including complex type gymnastics, build performance, debugging, and architectural decisions. If a specialized expert is a better fit, I will recommend switching and stop.

      Also in 3 projects that use this

    • xfstudioSkill

      typescript-advanced-types

      Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript projects.

      Also in 4 projects that use this

  • In this repository11 other files it gives its agents.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.