Github Stacked PR
🎯 What a “Stacked PR” Is (and Why You’ll Want One) A stacked pull request (sometimes called a stacked PR , stacked diff , or dependent PR ) is a series of PRs that build on top of each other, each one containing a small, logically‑isolated change. main ──► A ──► B ──► C │ │ │ │ │ └─ PR‑C (depends on B) │ └─ PR‑B (depends on A) └─ PR‑A (directly on main) A is based on main . B is based on A (its…
A "stacked pull request" (sometimes referred to as a stacked PR, stacked diff, or dependent PR) is a series of pull requests that build upon each other in a logical, sequential manner. Each PR in the stack introduces a small, isolated change, with the subsequent PR depending on the completion of the preceding one. For example, if PR A is based directly on the main branch, PR B is based on PR A, and PR C is based on PR B, then merging the stack (in order from A to C) ensures that each change is cleanly integrated, allowing reviewers to focus on one cohesive piece at a time.
Stacked PRs are particularly advantageous in scenarios where monolithic pull requests, which can be challenging to review and often lead to extended continuous integration (CI) times, are undesirable. By breaking down work into smaller, manageable PRs—such as a "feature flag," a "data model," or a "UI component"—teams can more easily isolate and address interdependent changes.
For instance, a new API might be introduced in one PR, followed by dependent changes like its consumer in subsequent PRs. While each dependent change resides in its own PR, they still benefit from combined testing because they're built on top of one another.
Continuously rebasing the stack on the main branch prevents the inclusion of unrelated changes, ensuring that only the initial PR in the stack requires rebasing onto main, while the remaining PRs remain on top of it. Early shipping of part of a larger change is facilitated by merging the first PR in the stack, with the subsequent PRs pending until they're ready.
CI resource usage is optimized since only the bottom PR runs the full suite against the main branch; higher PRs can execute a lighter subset of tests having already passed lower-level tests.
Several tools facilitate the creation and management of stacked PRs. GitHub's built-in features, such as draft PRs with "depends on" labels, offer a straightforward manual approach without requiring additional software. For automation, ghstack—a GitHub CLI plugin—provides an enhanced, GitHub-native solution, capable of automatically creating stacked PRs, managing base updates, resolving merge conflicts, and re-stacking after rebases.
Installation involves using GitHub CLI and pip to install the ghstack package, following with a series of commands to create and push the stack of commits. Alternatively, GitTown and gstack provide similar functionalities, with GitTown working across various repositories and gstack being a lightweight Bash script. Lastly, services like pullrequest.io offer a managed solution with visual stack tracking and automatic updates, though installation requires a machine-user token.
In summary, if a simple, no-installation-required solution is sufficient, using GitHub's native draft PRs with the "depends on" label might suffice. However, for automated, end-to-end management of stacked PRs, ghstack is the most comprehensive and GitHub-integrated option available in 2026.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.