Pull Request (PR) stacking is another name for stacked diffs, a concept that has existed for several years. We’ll discuss what it is, the tools we can use, and where PR stacking may benefit us.
In traditional Pull Requests (PRs), the developer makes all the changes in one or more commits and then opens the PR to merge the change into the main branch. The approach in PR stacking instead is to separate the functionality to be delivered into pieces. Let’s say we’re working on a new POST request API.
1️⃣ The first PR could be the happy path where what we submit works okay, and that would be opened against the main branch.
2️⃣ The next piece of work could be the error scenario when the payload is too large, and that PR would be created to merge into the branch from the first PR.
3️⃣ Another PR could be added for the scenario when the data being sent is not in a format the API can understand and would be stacked on top of the second PR.
A PR stack moves us away from having to deliver our significant change in one go with a long review. Instead, we break it down into pieces so they can be reviewed quickly.
We could perform PR stacking with the git command, but it doesn’t offer any of the features of a dedicated tool, such as:
applying the changes from the current PR to all of the PRs that are stacked on it by doing an automatic rebase
annotating our PR with the details of the entire PR stack
rebasing and restacking PRs when we merge or close a downstream PR
A challenge in community (open source) projects is that the dependent libraries can have new security vulnerabilities, or coding practices that change a lot.
The benefit to the reviewers is that they can see the changes and why with each PR, an essential aspect in community projects that helps with communication. This leads to faster reviews and the opportunity to continue building the functionality while feedback is gathered.
Now that we’ve learned about PR stacking, experiment with the different PR stacking tools. Look for opportunities to use the tools in the next feature or open-source submission. As with any experiment, please note the impact that PR stacking and the tool have on our work.
The lead image was generated using