DEV Community

Cover image for Getting Started with Stacked PRs on GitHub
Naveen Malothu
Naveen Malothu

Posted on

Getting Started with Stacked PRs on GitHub

What was released / announced

Stacked PRs are now live on GitHub, allowing developers to create a new pull request that depends on another pull request that has not been merged yet. This feature is currently in public preview and enables a more efficient way of managing complex code changes. With Stacked PRs, developers can create a chain of dependent pull requests, making it easier to manage and review large code changes.

Why it matters

As someone who works on building AI infrastructure and cloud systems, I can attest that managing complex code changes can be a real challenge. Stacked PRs matter because they enable developers to work on multiple features or bug fixes simultaneously without having to worry about merging them in a specific order. This feature is particularly useful for large-scale projects with multiple contributors, as it streamlines the code review process and reduces the likelihood of merge conflicts.

How to use it

To get started with Stacked PRs, you'll need to create a new pull request and then create another pull request that depends on the first one. Here's an example of how you can do this using the GitHub CLI:

gh pr create --title "Dependent PR" --body "This PR depends on #123"
Enter fullscreen mode Exit fullscreen mode

You can also use the GitHub web interface to create a stacked PR. Simply create a new pull request and then click on the "Depends on" dropdown menu to select the PR that you want to depend on.

To automate the process of creating stacked PRs, you can use GitHub Actions. For example, you can create a workflow that creates a new PR when a dependent PR is merged:

name: Create Dependent PR
on:
  pull_request:
    types: [merged]
jobs:
  create-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Create PR
        run: |
          gh pr create --title "Dependent PR" --body "This PR depends on #${{ github.event.pull_request.number }}"
Enter fullscreen mode Exit fullscreen mode

My take

As someone who builds AI infrastructure and cloud systems, I'm excited about the potential of Stacked PRs to streamline our code review process. In my experience, managing complex code changes can be a major pain point, especially when working with large teams. Stacked PRs have the potential to reduce the time it takes to merge code changes and get new features out the door. I'm looking forward to trying out this feature in our own workflows and seeing the impact it has on our productivity.

Top comments (0)