
GitHub’s recent introduction of stacked pull requests (PRs) marks a significant shift in how developers manage complex code changes. This feature allows teams to break down large updates into smaller, interdependent PRs, each building on the one before it. For example, foundational changes like database schema updates can form the base of the stack, while dependent updates, such as API or UI modifications, are layered above. Better Stack explores how this structured approach not only simplifies workflows but also improves collaboration and code review clarity by isolating changes into manageable segments.
In this preview, you’ll gain insight into the practical benefits of stacked PRs and how they integrate into GitHub’s ecosystem. Discover how the GitHub CLI commands, such as `gh stack init` and `gh stack submit`, streamline the creation and submission of PR stacks, reducing administrative overhead. You’ll also learn about the manual workflow option for teams with custom pipelines, as well as the built-in visual indicators that make navigating PR dependencies intuitive. This guide offers a comprehensive look at how stacked PRs can enhance your development process.
What Are Stacked PRs?
TL;DR Key Takeaways :
- GitHub’s new stacked pull requests (PRs) feature allows developers to break down complex code changes into smaller, interdependent PRs, improving workflow and code review efficiency.
- Stacked PRs create a hierarchical chain of dependencies, with foundational changes at the base and dependent updates layered above, simplifying development and review processes.
- Key benefits include improved code reviews, effortless merging with the “merge stack” feature, enhanced collaboration through clear dependency chains and reduced risk of errors.
- Developers can manage stacked PRs using GitHub’s CLI commands (
gh stack init,gh stack add,gh stack submit) or manually link PRs for flexibility. - Fully integrated into GitHub’s interface, stacked PRs are ideal for managing large-scale updates like database migrations, API development and UI overhauls, transforming modern development workflows.
Stacked PRs offer a structured approach to handling extensive code changes. Instead of submitting a single, monolithic PR, developers can divide their work into smaller, logically connected PRs. Each PR in the stack builds upon the changes introduced by the one before it, creating a clear and organized progression that simplifies both development and review processes.
- The first PR in the stack targets the default branch, such as
main. - Subsequent PRs target the preceding PR, forming a hierarchical chain of dependencies.
- Foundational changes, such as database schema updates, are placed at the base, while dependent updates, like API or UI modifications, are layered above.
This method isolates changes, allowing reviewers to focus on specific aspects of the code. By reducing complexity and improving clarity, stacked PRs make it easier to identify issues and provide actionable feedback.
Key Advantages of Stacked PRs
Managing large-scale code changes has traditionally been a challenging and error-prone process, often requiring manual rebasing, merging and extensive coordination. Stacked PRs address these issues by introducing a streamlined workflow that offers several significant benefits:
- Improved Code Reviews: Smaller, focused PRs reduce the cognitive load on reviewers, allowing them to evaluate changes more thoroughly and efficiently.
- Effortless Merging: The “merge stack” feature eliminates the need for manual rebasing, allowing seamless integration of all PRs in a stack with minimal effort.
- Enhanced Collaboration: Dependency chains provide clear context for changes, fostering better communication and alignment among team members.
- Reduced Risk: Isolating changes into smaller PRs minimizes the likelihood of introducing errors, as each PR can be tested and reviewed independently.
This feature is particularly beneficial for projects involving complex updates, such as database migrations, API development, or frontend and backend coordination.
Here is a selection of other guides from our extensive library of content you may find of interest on GitHub.
- RaspyJack : Tiny Raspberry Pi Zero 2W Network Toolkit for Security Testing & More
- BettaFish AI : Free Powerful Public Opinion Analysis Tool
- Play Cyberpunk 2077 on the AyaNeo Pocket DS with Armada OS
- Your Mac Already Has a Free AI Model Built in: Here’s How to Unlock It with Apfel
- How to Use GitHub Spec Kit : The Secret to Flawless AI Coding Projects
- Why Elon Musk Just Leased 220,000 GPUs to Anthropic
- LeCun Labels xAI a Failure as All 11 Co-Founders Depart
- Apple Watch vs Whoop vs Oura: Fitness Smart Features Compared
- iOS 18.0.1: When Will Apple Finally Release It?
- Why Elon Musk is Creating SpaceX AI for a Historic $2 Trillion IPO
How to Use GitHub CLI for Stacked PRs
GitHub’s Command Line Interface (CLI) simplifies the creation and management of stacked PRs with intuitive commands. These commands reduce administrative overhead, allowing developers to focus on coding rather than managing dependencies:
gh stack init: Initializes a new stack by linking PRs in sequence.gh stack add: Adds a new PR to an existing stack, maintaining the hierarchical structure.gh stack submit: Submits all PRs in the stack simultaneously, making sure smooth integration and deployment.
By automating much of the process, the CLI makes it easier to adopt stacked PRs, even for teams unfamiliar with the concept.
Manual Workflow for Stacked PRs
For teams that prefer not to use the CLI, stacked PRs can also be created manually. This involves linking PRs by setting the target branch of each PR to the previous one in the stack. While this method requires more effort, it offers flexibility for teams with unique workflows or tool preferences.
Manually managing stacked PRs allows developers to maintain complete control over the process, making sure compatibility with custom development pipelines or specific project requirements.
Integration and Usability Across GitHub
Stacked PRs are fully integrated into GitHub’s user interface, making them intuitive and accessible for developers. Key features of this integration include:
- Visual Indicators: Icons and dependency markers clearly display relationships between PRs, helping teams understand the structure of the stack at a glance.
- Workflow Integration: Stacked PRs are seamlessly incorporated into pull request pages, lists and workflows, making sure smooth navigation and usability.
- Merge Stack Functionality: A single action merges all PRs in a stack, streamlining deployment and reducing the risk of errors.
This seamless integration ensures that stacked PRs fit naturally into existing development processes, minimizing disruption while maximizing efficiency.
Applications and Industry Impact
Stacked PRs are particularly valuable for managing large-scale, multi-layered changes. They are well-suited for a variety of use cases, including:
- Database Schema Updates: Managing changes that impact multiple layers of an application, such as schema modifications that require corresponding updates to APIs and user interfaces.
- API Development: Incrementally building and refining API endpoints, making sure that each stage is thoroughly tested and reviewed before moving forward.
- UI Overhauls: Coordinating frontend updates that depend on backend modifications, allowing smoother transitions and reducing the likelihood of breaking changes.
Additionally, stacked PRs align well with AI-driven workflows, where automated tools generate or modify code in stages. By breaking down changes into smaller, manageable pieces, stacked PRs assist better integration with AI systems, improving overall efficiency and accuracy.
Early feedback from developers highlights the potential of stacked PRs to reduce bottlenecks, enhance team collaboration and improve the overall quality of code. As more teams adopt this feature, it is expected to become a standard practice for managing complex projects.
Transforming Development Workflows
GitHub’s stacked PRs represent a significant advancement in software development workflows. By breaking down complex changes into manageable pieces, this feature enhances code review efficiency, simplifies merging and fosters better teamwork. Whether you choose to use the GitHub CLI or prefer a manual approach, stacked PRs offer a powerful solution to the challenges of modern development. With seamless integration into GitHub’s ecosystem, stacked PRs are set to become an indispensable tool for developers tackling intricate projects.
Media Credit: Better Stack
Disclosure: Some of our articles include affiliate links. If you buy something through one of these links, Geeky Gadgets may earn an affiliate commission. Learn about our Disclosure Policy.