gh stack: which command builds, syncs and lands a stacked PR
gh stack is GitHub's CLI extension for native stacked pull requests: init, add and submit build a stack; rebase and push keep it current.
Install it with gh extension install github/gh-stack. gh stack link opens branches made in Jujutsu, Sapling or git-town as a stack, and gh stack merge lands everything up to the pull request you pick, all or nothing.
How do you install gh stack?
Run gh extension install github/gh-stack, sign in with gh auth login, and update later with gh extension upgrade stack. GitHub's two pages disagree on versions: the quickstart asks for GitHub CLI 2.90.0 and Git 2.20 or later, the CLI reference for GitHub CLI 2.0 and Git 2.36. Meet both: GitHub CLI 2.90.0 and Git 2.36.
For coding agents, GitHub publishes a skill: gh skill install github/gh-stack (quickstart). The extension has had 13 releases, from v0.0.1 on April 10, 2026 to v0.3.0 on October 26, 2026.
Which command creates a stack, and what does each one do?
gh stack init creates a stack, gh stack add puts the next branch on top, and gh stack submit pushes them and opens the linked pull requests. gh stack add -Am "message" stages, commits and starts the next branch in one step.
gh stack commands, from GitHub's CLI reference
| Command | What it does | When you run it |
|---|---|---|
gh stack init | Starts a stack: creates or adopts the first branch on the trunk | Once, at the start |
gh stack add | Adds a branch on top of the current stack | For each next layer |
gh stack view | Shows every branch, its pull request, status and last commit | Any time |
gh stack checkout | Checks out a stack by stack number, PR number, URL or branch | To pick up a stack |
gh stack modify | Restructures the stack: reorder, drop, insert, rename | From a clean tree |
gh stack unstack | Removes the stack on GitHub and locally (alias: delete) | Before rebuilding a stack |
gh stack submit | Pushes every branch, opens or updates the PRs and links the stack | When layers are ready |
gh stack sync | Fetches, rebases if the trunk moved, pushes and syncs PR state | To catch up |
gh stack rebase | Cascading rebase from the trunk up (--upstack, --downstack) | After a lower layer changes |
gh stack push | Pushes active branches in one atomic push, with --force-with-lease | After a rebase |
gh stack link | Links branches or PRs into a stack on GitHub, no local tracking | From Jujutsu, Sapling or git-town |
gh stack merge | Merges the stack up to a chosen PR, all or nothing | To land it |
gh stack switch / up / down | Moves between branches in the stack | While working |
gh stack top / bottom / trunk | Jumps to the top, the bottom or the trunk | While working |
gh stack alias / feedback | A short alias; feedback to GitHub | Rarely |
What do gh stack rebase, sync and push each do?
rebase rewrites, push uploads, and sync does both only when the trunk moved.
- rebase fetches, then rebases each branch onto the one below, from the trunk up. After a merged layer it switches to
--ontoby itself.--upstackstops at the top,--downstackat the current branch. - push sends every active branch in one atomic push with
--force-with-lease. It never opens pull requests;submitdoes. - sync fetches, pulls in layers others added on GitHub, fast-forwards the trunk, rebases only if the trunk moved, pushes, and links the stack. On a conflict it puts every branch back and tells you to run
rebase.
On github.com, the Rebase stack button does the same server-side and force-pushes each branch. GitHub's October 6 changelog says those commits are now signed; its Managing page still says server-side rebase commits are not, so rebase from the CLI if your repository requires signatures.
How do you fix a conflict mid-rebase?
Fix the files, stage them, and continue; the rest of the stack rebases on its own.
git add .
gh stack rebase --continue # or: gh stack rebase --abort to put every branch back
gh stack push
A stopped gh stack modify has its own pair: gh stack modify --continue or --abort, which restores a snapshot taken before it started.
How do you link a stack built in Jujutsu or git-town?
List the branches bottom to top: gh stack link change1 change2 change3. It pushes them, opens a draft pull request for any branch without one, fixes each base, and links the stack.
Pass existing pull request numbers the same way (gh stack link 10 20 30), add --open for ready-for-review pull requests, or --base develop for another trunk. Link keeps no local tracking; to get rebase and sync, adopt the branches with gh stack init change1 change2 change3.
What can't gh stack do?
It can't stack across forks: every branch must be in the same repository. Stacks aren't in GitHub Desktop, and on github.com a reorder means unstacking and rebuilding, while gh stack modify reorders in place. gh stack merge can't bypass merge requirements.
Exit codes, for scripts and agents
| Exit code | Meaning |
|---|---|
| 0 | Success |
| 1 | Generic error |
| 2 | Not in a stack, or stack not found |
| 3 | Rebase conflict |
| 4 | GitHub API failure |
| 5 | Invalid arguments or flags |
| 6 | Branch belongs to more than one stack |
| 7 | Rebase already in progress |
| 8 | Stack is locked by another process |
| 9 | Stacked pull requests are not enabled for this repository |
| 10 | Modify session interrupted; recovery needed |
GitHub's rollout guide says stacks need no setup or enablement, yet code 9 exists for a repository where they are not enabled; GitHub's docs don't say which setting causes it.
Which big projects already use stacks?
18 of the 100 most-starred repositories have a stacked pull request among their 100 most recently updated merged pull requests: 173 stacked of 9,309 read, in 69 stacks.
The repositories with the most stacked pull requests
| Repository | Stacked PRs | Largest stack | Stack base |
|---|---|---|---|
| react/react | 45 | 23 | main |
| n8n-io/n8n | 18 | 12 | master |
| immich-app/immich | 17 | 6 | main |
| vercel/next.js | 15 | 4 | canary |
| supabase/supabase | 15 | 7 | master |
| NousResearch/hermes-agent | 10 | 5 | main |
| microsoft/PowerToys | 10 | 13 | main |
| langflow-ai/langflow | 8 | 3 | release-1.14.0 |
| mattpocock/skills | 6 | 2 | main |
| langgenius/dify | 6 | 4 | main |
Method. The 100 most-starred GitHub repositories with a programming language as their main language, not archived and not forks, read December 3, 2026. For each, GitHub's GraphQL API returned its 100 most recently updated merged pull requests with the read-only stack and stackEntry fields. A repository whose 100 pull requests reach back before the July 30 preview could not have stacked them all. Download the CSV (one row per repository, CC BY 4.0).