GitHub Stacked PRs: a practical guide to gh stack
By Flavio
Updated
Tagged: Git
Learn GitHub Stacked PRs with gh stack: design focused layers, submit the chain, handle review feedback, rebase safely, and merge.
GitHub Stacked PRs let you split one large change into several small pull requests that depend on each other.
Each pull request stays focused so reviewers see one layer at a time, while you can still merge the whole feature in one go.
This solves a problem I often see with large features: the code is ready, but the pull request is too big to review well.
Instead of opening one 2,000-line pull request, you might open 3 smaller ones:
- a data model
- an API built on that model
- a user interface built on that API
The pull requests form a chain. GitHub understands that chain, shows it in the UI, runs checks for every layer, and helps keep all the branches up to date.
In this tutorial we’ll build one stack from start to finish. We’ll also change a branch in the middle, resolve a rebase conflict, and see what happens when we merge only part of the stack.
GitHub Stacked PRs went generally available on October 6, 2026, after a public preview that started July 30. Stacks go through the merge queue as a single merge group. See the GA announcement.
The problem with one large pull request
Imagine we’re adding user search to an application.
The feature needs 3 parts:
- types and data access
- an API endpoint
- a search interface
We could put everything on one branch:
main
└── user-search
That gives us one large pull request.
The reviewer has to understand the data layer, API, and interface all at once. A small concern about the data model can invalidate comments already made on the UI.
We could also create 3 independent branches from main:
main
├── user-model
├── search-api
└── search-ui
That doesn’t model reality, though, because the API needs the data model and the UI needs the API.
A stack represents that dependency:
main
└── user-model
└── search-api
└── search-ui
The first branch starts from main, the second from the first, and the third from the second.
A stack is both cumulative and divided
There are two useful ways to look at a stack.
Git sees cumulative branches. The search-ui branch contains the model, API, and UI because it descends from both lower branches.
The pull request interface shows divided changes:
PR #1: main → user-model
PR #2: user-model → search-api
PR #3: search-api → search-ui
PR #2 shows only what changed between user-model and search-api, without repeating the model. PR #3 shows only the UI layer.
That gives the reviewer small diffs without pretending the changes are unrelated.
What GitHub adds to the old stacked-branch workflow
Developers have stacked branches for years. You can do it with regular Git commands and ordinary pull requests.
GitHub’s feature adds a first-class Stack object around those PRs, which gives you:
- a stack map in the pull request header
- navigation between every PR in the stack
- branch protection and CODEOWNERS checks based on the final target branch
- GitHub Actions runs for every layer as if it targeted the final branch
- a cascading rebase for the entire chain
- partial or full stack merges from one merge action
- stack data in the REST API, GraphQL API, and webhooks
The branches and pull requests are still normal Git branches and PRs. The chain of PR base branches is the Git structure, while the Stack object is the GitHub layer built around it so GitHub knows how they fit together.
Before you start
You need:
- Git 2.20 or later
- GitHub CLI 2.0 or later
- a GitHub repository you can push to
If you’re new to the basics, read my Git guide and first GitHub pull request tutorial first.
Check that GitHub CLI is authenticated:
gh auth status
Then install the official extension:
gh extension install github/gh-stack
Upgrade an existing install with:
gh extension upgrade stack
From 0.2 on, gh stack can work with Git worktrees. Cross-worktree rebase and sync need Git 2.36 or later.
If gh stack later warns that stacked PRs aren’t enabled for this repository, see How to fix “Stacked PRs are not enabled for this repository”.
You can use gh stack for every command. The extension can also create a shorter gs command:
gh stack alias
I’ll stick with the full command in this tutorial so each example is easy to recognize.
Create the first layer
Start from an updated main branch:
git switch main
git pull --ff-only
Now initialize a stack and name its first branch:
gh stack init user-model
This creates and checks out user-model, and records the new stack in .git/gh-stack.
Because that file lives inside .git, it’s purely local metadata and won’t get committed to your repository.
The command also enables Git’s rerere (“reuse recorded resolution”) feature. If the same conflict shows up during several cascading rebases, Git remembers how you resolved it.
Say we add the user model and its tests, then commit that first focused change:
git add src/users.ts tests/users.test.ts
git commit -m "Add user search model"
The bottom of our stack now looks like this:
main
└── user-model
This branch should make sense on its own, so a reviewer can check the model without thinking about HTTP or interface code.
Add the API layer
The API depends on the model, so it belongs above user-model.
Add a branch to the top of the stack:
gh stack add search-api
gh stack add creates the branch at the current HEAD and checks it out.
Add the API code and commit it:
git add src/api/search.ts tests/search-api.test.ts
git commit -m "Add user search endpoint"
The stack now has two layers:
main
└── user-model
└── search-api
Notice that search-api contains the model commits too, since the endpoint uses the model.
Its pull request won’t repeat them, though. Because the PR base is user-model, the diff only contains the API changes.
Add the interface layer
Let’s add one more branch:
gh stack add search-ui
Then add and commit the interface:
git add src/components/UserSearch.ts tests/user-search.test.ts
git commit -m "Add user search interface"
We now have the full chain:
main
└── user-model
└── search-api
└── search-ui
This is a good stack because every dependency arrow points down: the UI depends on the API, the API depends on the model, and nothing in user-model depends on a branch above it.
Inspect the stack before publishing it
Use gh stack view to see the current stack:
gh stack view
You can also ask for a compact list:
gh stack view --short
Or get JSON for a script:
gh stack view --json
I also like to inspect each layer with regular Git before submitting:
git diff main..user-model
git diff user-model..search-api
git diff search-api..search-ui
It’s a quick sanity check. If that last command shows changes to the data model, some work probably ended up on the wrong branch.
Create the pull requests
Submit the stack:
gh stack submit
This command pushes all branches, creates or updates the pull requests, and links them as a Stack on GitHub.
It also gives every PR the right direct base:
user-model → main
search-api → user-model
search-ui → search-api
The command opens an editor so you can accept the generated titles, write clearer ones, and toggle each new PR between ready and draft.
For a non-interactive submission, use generated titles:
gh stack submit --auto
New PRs created by --auto are drafts by default. Add --open when you want them ready for review:
gh stack submit --auto --open
If you only want to push the branches without creating or updating PRs, run:
gh stack push
It’s worth keeping the three commands straight:
pushupdates branchessubmitupdates branches, PRs, and the GitHub Stacksyncfetches, rebases, pushes, and reconciles local and remote state
Create a stack on GitHub.com
You don’t have to use the CLI.
Create the first pull request as usual. When you create the next one, set its base to the branch below it and select Create stack.
GitHub also detects existing pull requests that form a branch chain. When the chain is eligible, GitHub shows a banner that lets you turn those pull requests into a stack.
The CLI is still handy for rebasing and maintaining your local branches, but you can create, review, and merge a stack right from GitHub.com.
How reviewers should read a stack
Review a stack from the bottom up.
For our example, go in this order:
user-modelsearch-apisearch-ui
The lower layers establish the concepts used above them. Starting from the UI forces the reviewer to guess how the API and model work.
GitHub shows a stack map at the top of every PR, so reviewers can jump between layers without heading back to the repository’s PR list.
Each review is still independent. A reviewer can approve the model, request changes on the API, and leave the UI untouched.
My advice is to write each PR description for its own layer. Mention the larger feature, but explain exactly what that PR adds and what it deliberately leaves for the next one.
Change a branch in the middle of the stack
Without tooling, changing a branch in the middle is where stacked PRs get tedious.
Suppose a reviewer asks us to change the API while we’re working on search-ui.
Move down one branch:
gh stack down
You can also select the branch by name:
gh stack checkout search-api
Make the requested change where it belongs:
git add src/api/search.ts
git commit -m "Validate empty search queries"
Now search-ui is still based on the old tip of search-api, so the history isn’t one clean chain anymore.
Rebase every branch above the current one:
gh stack rebase --upstack
Then push the rewritten branches:
gh stack push
gh stack push uses an explicit --force-with-lease check for every branch, so you won’t overwrite unexpected remote work.
The multi-branch push isn’t atomic, so one branch may update while another is rejected. Fix the rejected branch and run the command again.
This is the daily rhythm of stacked development:
change the correct layer
↓
rebase the layers above it
↓
push the updated stack
Don’t put an API fix on the UI branch just to avoid a rebase. That muddies the UI diff and defeats the point of the stack.
Rebase the entire stack on main
While we work, other changes keep landing on main.
Update the entire chain with:
gh stack rebase
This runs a cascading rebase locally. gh stack starts at the trunk and works upward:
- rebase
user-modelonto the latestmain - rebase
search-apionto the newuser-model - rebase
search-uionto the newsearch-api
Then push:
gh stack push
You can also run the all-in-one command:
gh stack sync
sync fetches remote changes, updates the trunk, rebases the stack, pushes it, updates PR state, and reconciles the local stack with GitHub.
Use rebase when you expect to resolve conflicts interactively, and sync for the routine case where you want everything brought up to date.
Resolve a cascading rebase conflict
A conflict in a lower layer can ripple up through every branch above it. Start the rebase like you normally would:
gh stack rebase
If Git stops on a conflict, open the reported files, fix the conflict markers, and stage them:
git add src/users.ts
Then continue the rebase:
gh stack rebase --continue
The command picks up where it left off and works through the remaining branches. If the rebase starts going in the wrong direction, abort it:
gh stack rebase --abort
That puts every branch back to its pre-rebase state.
This is also where the automatically enabled rerere option pays off. Once you resolve a conflict on one branch, Git records it and can reuse the same resolution if a similar conflict shows up higher in the stack.
Rebase locally or on GitHub
GitHub also gives you a Rebase Stack button right in the pull request UI. When the rebase is clean, the server rebases every unmerged branch and force-pushes the updated history for you. The new commits stay signed, and existing approvals aren’t wiped out even if your repo normally dismisses stale reviews.
If you expect conflicts, use the CLI instead. Server-side rebase isn’t available when conflicts need manual resolution, so doing it locally lets you fix them in your editor.
Merge the whole stack
Once every layer is approved and all checks pass, merge the top PR. You can do it on GitHub.com or from the terminal:
gh stack merge
The interactive prompt lets you pick how much of the stack to merge and which merge method to use. GitHub then merges that PR along with every unmerged PR below it, from bottom to top.
For our stack, merging search-ui lands all 3 PRs in order:
user-model → search-api → search-ui
All 3 GitHub merge methods work here:
- squash merge creates one squashed commit per PR
- rebase merge replays all commits onto the target branch
- merge commit creates one merge commit per PR and preserves the branch commits
The squash behavior is especially nice: a stack of 3 PRs turns into 3 focused commits on main instead of one giant squash commit.
A direct stack merge is atomic, so either every selected PR lands or none of them do. If you use a merge queue, GitHub treats the stack as a single merge group that enters and lands together.
A few edge cases are handled cleanly too. Bypass permissions apply to stacks, so if you can bypass branch rules, you can merge the lowest unmerged PR. Auto-merge for stacks is rolling out separately, so you might not have it on every repo yet. And if a stack branches off another stack whose base branch gets deleted, GitHub retargets the remaining PRs instead of closing the bottom one.
Merge only part of the stack
You don’t have to merge the whole thing at once. Say the model and API are ready, while the UI still needs work. Merge the search-api PR, and GitHub lands those first two layers:
user-model → search-api
The search-ui PR stays open. GitHub retargets it to main and rebases its unique commits onto the updated trunk.
You can’t merge a middle PR while leaving a lower one unmerged, since every PR pulls in all unmerged layers below it. That follows the code dependencies: the API can’t land without the model it relies on.
After a partial merge, sync your local stack:
gh stack sync --prune
That updates the remaining branches and cleans up local branches for the PRs that already merged.
Once every PR in a stack is merged, that Stack object is finished and you can’t extend it. If you add new local branches later and submit them, the CLI starts a fresh stack from the trunk.
How squash merges avoid fake conflicts
Squash merging normally causes trouble for dependent branches. Suppose the bottom PR has commits A and B, and the branch above it has A, B, C, and D.
After a squash merge, main gets a new commit S1 instead of A and B:
before: main ← A ← B ← C ← D
after: main ← S1
A plain rebase often tries to replay A and B even though their changes are already inside S1. That triggers fake conflicts caused by the new commit hashes rather than real code differences.
GitHub’s stack rebase avoids this by finding the unique commits and running git rebase --onto so only C and D replay on top of S1. The remaining branch ends up looking like this:
main ← S1 ← C' ← D'
Handling that cleanly after merges rewrite history is one of the biggest reasons to use stack-aware tooling instead of juggling dependent branches by hand.
GitHub Actions and the CI multiplication problem
GitHub evaluates every PR in a stack as if it targeted the stack’s final base, usually main. Any workflow configured for pull requests into main runs on every PR in the chain, and required checks and branch protection apply to every layer too.
That closes a common gap in manual stacks, where only the bottom PR triggers the right checks. The flip side is higher CI usage: a stack of 5 PRs can end up running the same expensive integration suite 5 times.
Because the pull_request webhook doesn’t expose a stack object, the easiest workaround is to mark a standalone PR or the top PR explicitly with a label like run-integration:
jobs:
integration:
if: >-
contains(
github.event.pull_request.labels.*.name,
'run-integration'
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: npm ci
- run: npm run test:integration
Add labeled to the workflow’s pull_request activity types if you want applying the label to kick off the run right away, and remember to remove or move the label when the top of the stack changes.
In practice, keep fast checks running on every layer so reviewers can trust each focused diff, and save slow end-to-end suites for the top PR when that tradeoff makes sense for your repo.
One subtle catch: GitHub evaluates CODEOWNERS from the stack base. If PR #1 edits CODEOWNERS, those updated rules don’t control reviews for PR #2 yet because the change hasn’t landed on the final base.
Bring existing branches into a stack
You don’t have to start from scratch with gh stack init. If you already have dependent branches locally, list them from bottom to top:
gh stack init user-model search-api search-ui
Then submit the stack:
gh stack submit
GitHub detects existing PRs and links them when possible.
If you already like another local stacking tool, keep using it. Because GitHub works with standard branches and PRs, tools like Jujutsu, Sapling, and git-town can manage the local chain while gh stack link sets up the relationship on GitHub:
gh stack link user-model search-api search-ui
That doesn’t create local gh stack tracking. It pushes the branches, creates or finds their PRs, fixes the base branch chain, and links everything on GitHub.
Restructure a stack
Sometimes your first plan turns out wrong. Maybe the API PR grew too big, two tiny branches make more sense combined, or a layer belongs lower in the dependency chain.
Open the interactive editor to reshape it:
gh stack modify
From there you can:
- drop a branch from the stack
- fold one branch into an adjacent branch
- insert a branch
- reorder branches
- rename branches
- preview and undo changes before applying them
Your working tree needs to be clean, and the stack has to have a linear history. Once you’ve applied your changes, push the updated structure to GitHub:
gh stack submit
Restructuring is handy, but do it early. Reordering layers after detailed reviews are already underway creates extra work for your reviewers.
Use stacks with AI coding agents
GitHub publishes an agent skill for gh-stack that you can install directly:
gh skill install github/gh-stack
Or you can grab it with the Skills CLI:
npx skills add github/gh-stack
The skill teaches a compatible coding agent how to plan layers, create branches, navigate the stack, and rebase after mid-stack edits.
Stacks fit agent workflows well. An agent can generate a big diff fast, yet whoever reviews it still needs clean boundaries to follow. Anyone can tell an agent to split a big diff into 5 PRs, but the split only helps if the dependency order makes sense and each layer is coherent on its own. Review that plan before the agent starts moving commits around.
How to design a good stack
A good stack isn’t one PR per commit. Start a new layer when the concern, dependency, or reviewer changes.
Good natural boundaries look like this:
- schema before code that reads the schema
- shared types before their consumers
- core logic before delivery code
- API before interface
- implementation before integration tests for the whole feature
- production code before documentation, when docs depend on the final behavior
Stick to one effort per stack. A search UI and an unrelated billing fix shouldn’t share a chain.
I aim for every layer to fit one sentence:
This PR adds ___ so the next layer can ___.
If that sentence needs 3 “and” clauses, the layer is probably too broad.
Avoid very deep stacks too. Smaller PRs make reviews easier, but every extra layer adds CI runs, branches, rebases, and review state to track. Three clear PRs are usually better than 12 tiny ones.
When not to use a stack
If a change is already small and self-contained, stick with a regular pull request.
Don’t reach for a stack when:
- every branch can target
mainindependently - the change takes less time to review than the stack takes to explain
- you need branches across different forks, which GitHub Stacked PRs doesn’t support
- your team isn’t comfortable with rebasing rewritten branches
- the feature can’t be split into coherent layers
Stacks earn their keep on dependent work that’s too big for one review, yet too tightly connected to ship as independent PRs.
The commands I would remember
You don’t need to memorize the whole CLI. These commands cover most of the day-to-day workflow:
gh stack init user-model # start the first layer
gh stack add search-api # add a layer on top
gh stack submit # push and create/update PRs
gh stack view # inspect the stack
gh stack up # move away from trunk
gh stack down # move toward trunk
gh stack rebase # cascade changes through the stack
gh stack push # push every branch
gh stack sync # fetch, rebase, push, and sync state
gh stack modify # restructure the stack
gh stack merge # merge part or all of the stack
The mental model matters more than the exact flags:
foundations at the bottom
dependencies above them
review from bottom to top
change code in the layer where it belongs
rebase everything above that layer
Once that clicks, gh stack handles most of the branch bookkeeping for you.
You can check the latest commands in the official GitHub Stacked PRs documentation and the github/gh-stack repository.
Want me to talk about your product? You can sponsor this site.
Related posts about git: