Magic Tools
Developer ToolsBy CooconSeptember 4, 202610 views5 min read

GitHub Native Stacked PR Tutorial: How to Use the gh stack Command, How to Merge, and How to Convert Old Branches

GitHub Native Stacked PR Tutorial: How to Use the gh stack Command, How to Merge, and How to Convert Old Branches

First, let's clarify the most common questions searchers have:

  • What is this: Stacked PR = split a large change into a series of small PRs with dependent order, each PR contains only the diff for its layer, review layer by layer, and finally merge the entire stack with one click.
  • When was it launched: GitHub made it a native feature and opened public preview on July 30, 2026, gradually rolling out to all repositories—before this, you could only simulate it with third-party tools like Graphite, spr, or git-branchless.
  • Is it paid: No, it's not a paid plan exclusive feature. The CLI extension gh-stack is free to install.
  • Where to use: Supported on github.com web, gh command line, and GitHub mobile; there's also a companion AI agent skill.

1. Five-Minute Quickstart: Building a Stack from Scratch

Prerequisite: Install GitHub CLI (v2.0+, official packages available for Windows/macOS/Linux), then install the official extension:

gh extension install github/gh-stack

Core mental model: a stack is a sequence of ordered branches, each layer built upon the next, with the base layer on the trunk (usually main):

frontendPR #3 (base: api-endpoints) ← 顶层
api-endpointsPR #2 (base: auth-layer)
auth-layerPR #1 (base: main)          ← 底层
─────────────
main (trunk)

Complete workflow:

# 1. 建 stack(创建并切到第一个分支)
gh stack init

# ...在第一层提交代码...

# 2. 在上面叠一层
gh stack add api-endpoints
# ...继续提交...

# 3. 推送所有分支
gh stack push

# 4. 查看整个 stack
gh stack view

# 5. 一次性开出整串 PR(每层一个,base 自动指向下一层)
gh stack submit

After submit, GitHub links this series of PRs into a Stack object: each PR page shows a stack map at the top, reviewers can see the current layer's position in the entire change, and each PR only displays the diff for its layer.

A handy trick: gh stack add -Am "Add login endpoint" can complete "stage all changes + commit + auto-generate branch name by date + add new layer" in one command.

2. Review and Merge: The Three Key Rules

  1. Each layer can be reviewed in parallel. Different colleagues reviewing different layers don't block each other, which is exactly its solution to the pain point of "PRs getting larger in the AI era." In the official announcement, TED's CTO was straightforward: AI made developer output explode, and review became the new bottleneck; splitting large changes into dependent small blocks means "review is not just faster, but more accurate."
  2. You can merge only a subset. Merging one or several lower layer PRs, the upper PRs will remain open and automatically rebase and redirect the base (e.g., after PR #1 merges into main, PR #2's base automatically changes to main).
  3. You can also merge the entire stack with one click. Merging the topmost "ready" PR, it and all unmerged layers below will land all at once. Branch protection and required checks still apply, governing what ultimately enters main.

Merge queue support for stacks will roll out gradually in the weeks after public preview—teams heavily relying on merge queue should confirm their repository is enabled before use.

3. Converting Existing Branches/PRs to a Stack

No need to start over. gh stack init supports adopting existing branches:

# 把两个已存在的分支按顺序收编成一个 stack
gh stack init feature-auth feature-api

# 主干不是 main?指定 trunk
gh stack init --base develop feature-auth

Colleagues' stacks can also be pulled down and continued:

gh stack checkout 42        # 按 PR 号
gh stack checkout <PR URL>  # 按 PR 链接
gh stack checkout           # 交互式选择器,列出本地+远端所有 stack

4. Daily Maintenance: Rebase and Sync

When the base layer changes or main advances, how do the upper layers follow? Two commands:

# 拉取远端 + 从主干向上逐层级联 rebase
gh stack rebase

# 一条命令完成:拉取、对齐远端 stack、级联 rebase、推送、同步 PR 状态
gh stack sync

In detail, the official implementation is quite thoughtful: init automatically enables git rerere (conflict resolutions are remembered, so rebasing across layers doesn't require resolving the same conflict repeatedly); on rebase conflicts, it prints the conflicted files and line numbers, after resolving and git add, use gh stack rebase --continue, to abort entirely and return to the pre-rebase state use --abort; when a layer's PR has been merged, rebase automatically switches to --onto mode to replay commits correctly.

Stack metadata is stored locally in .git/gh-stack (a JSON file, not committed to the repository).

5. Frequently Asked Questions (FAQ)

Is Stacked PR a paid feature?

No. It's rolling out gradually to all repositories during public preview, and the CLI extension is free.

Can you merge only one PR in a stack?

Yes, but direction matters: merge a lower layer, the upper layers automatically rebase and redirect, staying open; merge an upper layer, all unmerged layers below will land together. To land them one by one, start from the bottommost layer.

Can it be used on Windows?

Yes. gh CLI officially supports Windows/macOS/Linux, and gh-stack is installed cross-platform via gh extension install with consistent command behavior.

Can stacks be created on the web, or must you use the command line?

Officially, stacks can be operated on github.com, CLI, and mobile: the web flow is to create the first PR, then layer branches and PRs on top (each PR's base points to the next layer). The command-line init/add/submit is the most efficient path.

How does it compare to third-party tools like Graphite or spr?

The biggest difference is being native: stack maps are built directly into PR pages, branch protection/required checks/merge queue are officially integrated, and reviewers don't need to install anything. The gaps third-party tools filled for years (cascading rebase, automatic base redirection) are now platform-native behaviors.

Can AI coding agents use it?

An official companion skill is released: gh skill install github/gh-stack, and once installed, your AI agent (e.g., Copilot, Claude Code) knows how to use the full suite of gh stack commands to manage stacked PRs.

When will it officially GA?

No timeline has been announced; it's currently in public preview, and features may change. Feedback channels are the official stacks discussion (gh.io/stacks-feedback).

References

Related Articles

How to Fix Claude Code Error: temporarily unavailable, so auto mode cannot determine the safety of bash

Claude Code auto mode pops up 'temporarily unavailable, so auto mode cannot determine the safety of bash'? First, the conclusion: it's not your command that's dangerous; it's the safety classifier (an additional model call) that's temporarily unavailable. This article provides a four-step fix, a complete variant lookup for model name × tool name × reason, and a mechanism explanation for why read-only operations are unaffected.

pitfallsSep 4, 20265 min
13

How Large a Local LLM Can a 24GB Mac mini Run? A Summary of Memory Budgets, Measured Speeds, and Acceleration Methods

What models can a Mac mini with 24GB unified memory actually run? The answer: 27B with 4-bit quantization is the ceiling, and we successfully ran Qwen3.8-27B on the base M4 Mac mini—peak memory 19.4GB, 11.7-12.2 tok/s with speculative decoding. This article summarizes all measurements on this machine: memory budgets for various model sizes, speed expectations, real effects of three acceleration methods (DFlash 2 / native MTP / MLX vs llama.cpp), and how to choose quantization levels.

ai-tutorialsSep 4, 20266 min
10

How Much Precision Does Large Model Quantization Actually Lose? Q8 to Q2 Explained in One Table, with GGUF Selection Guide

Does 4-bit quantization make models stupid? Can Q3 still be used? This article is based on llama.cpp official measured data for Llama-3-8B's full quantization levels, explaining the precision loss for each level from Q8_0 to IQ1_S, providing a specific selection path of 'choose the highest level that fits in memory', and answering common questions like how much difference between Q4 and Q8, what imatrix is for, and what 1.58-bit is about.

ai-tutorialsSep 4, 20269 min
13

Dev Breakfast · 2026-09-04

Today's headline: OpenAI Releases GPT-6 Astra: Recurrent Architecture and ARC-AGI-3 Performance Become Discussion Focus. Plus 7 more: Hardcoding Feature Flags: Engineering Trade-offs to Skip Remote Configuration; Nvidia Acquires Hugging Face: Open-source AI Community Faces Its Biggest Variable; and more.

daily-intelSep 4, 20266 min
33

Published by Magic Tools