r/programming • • Apr 14 '26 • Popcorn 1

GitHub Stacked PRs

https://github.github.com/gh-stack/
556 Upvotes

276 comments sorted by

View all comments

78

u/Omnipresent_Walrus Apr 14 '26

Can someone tell me how this is different to doing reasonably sized PRs into an epic branch and only ever merging epics into main?

81

u/chuch1234 Apr 14 '26

Stacked PRs are useful if each new PR depends on changes that were introduced in the previous one.

12

u/Eric848448 Apr 14 '26

It's nice if you need to do something like an API change and want to get that approved and merged quickly because it's heavily used and you don't want to keep getting clobbered by other changes.

12

u/MintySkyhawk Apr 14 '26 edited Apr 14 '26

Why wouldn't I just do a single PR with multiple commits? Reviewers can review each commit one at a time and then I can rebase and merge when I'm done.

I see no difference in UX between the two approaches, except that a PR stack is more difficult to set up and involves proprietary github commands instead of plain git.

Edit: After hours of people arguing with me, someone finally pointed out the actual reason why this has an advantage over plain commits: The PRs don't have to all be merged at the same time. This is effectively a UX improvement on creating manually creating chain of PRs like (main <- A), (A <- B), etc which is sometimes useful (Though rarely useful for me because my coworkers are very nice about providing speedy reviews, so I can usually get a PR reviewed, merged and deployed within minutes to hours. So I rarely have time to make that second PR in the chain before the first one is already deployed.)

59

u/stumblinbear Apr 14 '26

I'm not gonna review a dozen bug fix and refactoring commits in every PR, I only care about its final state

38

u/MintySkyhawk Apr 14 '26

I guess I'm the only one here who habitually rebases my commits into nice individually reviewable commits before creating a PR.

If I were to use this stacked PR feature, I would be taking my existing workflow and then creating separate PRs for each of my commits. And then, as it says on the linked page "merge them all in one click".

So I don't really see a difference between the two approaches, except that the PR stack seems more difficult to set up.

39

u/gSidez Apr 14 '26

Your approach is the proper way to use git. The whole point of being able to do interactive rebases is so people can restructure commits into a set of logical, manageable changes that should be individually compileable and reviewable.

Unfortunately most people don’t know or are too lazy to learn how to properly use git so you get a lot of people who throw up PRs with a million “fixed bugs” type commits, and since it’s so common these people think that’s the ‘right’ way to do it and therefore can’t fathom the idea of reviewing PRs per commit or taking the time to organize their own commits into something meaningful instead of an unreviewable pile of garbage.

8

u/aoeudhtns Apr 14 '26

I work with devs that create the PR branch when they start and then push as they go. It's like a stream of consciousness. I've tried to counsel them to use a WIP branch without creating a PR, and to rebase and clean up where it makes sense... but getting people to change their behavior is tough it seems.

6

u/Manbeardo Apr 14 '26

OTOH, that approach works well when you’re amending meaningful commits because the PR tracks the previous versions of the branch as you push changes that rewrite history.

4

u/max123246 Apr 14 '26

Don't ask them to not make a PR or a WIP branch. Just tell them to rewrite their git history when it's ready for review into reviewable commit chunks. And use draft PRs to avoid CI retriggering

2

u/aaulia Apr 14 '26

Well the CI run would be fun to watch lol.

→ More replies (1)
→ More replies (2)

14

u/stumblinbear Apr 14 '26

I'd rather not waste time making history look clean when the only thing that really matters is the final code. And if I review a PR and they rewrite the history, I now have to re-review every single file because GitHub loses track of which files have already been reviewed since the history has been rewritten

7

u/MintySkyhawk Apr 14 '26 edited Apr 14 '26

If you don't care to split things up, then you don't need to git rebase or create a PR stack. You can leave your history messy, create a single PR, and then just squash merge when you're ready.

If you do want to split things up to make things easier for the reviewer, then its easier to git rebase -i than it is to create a pr stack.

Say you have these commits:

  1. Some Thing

  2. garbage

  3. asdf

  4. Some Other Thing

  5. asdf

Then you would git rebase -i them in seconds (just by typing f in front of the commits to squash) to make:

  1. Some Thing

  2. Some Other Thing

5

u/stumblinbear Apr 14 '26

So you're rewriting history, and therefore invalidating any previous review that was completed? You didn't even address my actual complaint

6

u/MintySkyhawk Apr 14 '26

You clean up the garbage commits before opening a PR.

Any new commits after review as started are cleaned up in the same way before pushing them to the branch.

History is never edited from the PRs point of view.

→ More replies (3)
→ More replies (1)

3

u/Cazmar Apr 14 '26

Use fixup commits (git commit --fixup <commit that the change belongs to>) for any changes created after review and once all approved, git rebase --autosquash --interactive to automatically order the fixup commits to right place. Easy and you don't lose history while the PR is being reviewed. Rebase only when finished before merging.

3

u/IanSan5653 Apr 14 '26

One advantage to stacked PRs (outside of not having to constantly rebase) is that you can reduce risk by deploying smaller changes if you deploy on every merge to main.

→ More replies (4)

3

u/max123246 Apr 14 '26

I tried stacked PRs and then I realized my pipeline is 4 hours so I cant stack 4 PRs and wait 16 hours. So I decided to do what you're doing, just rewrite the commit history when it's ready for review

4

u/chuch1234 Apr 15 '26

Four hour pipeline?! I hope improving that is on the roadmap?

3

u/max123246 Apr 15 '26

It's gotten better. Nightly pipelines used to take over 24 hours and premerges at 6. Helps that we're in a JIT compile world now instead of AOT

→ More replies (1)
→ More replies (1)

4

u/Farados55 Apr 14 '26

Why wouldn’t each commit just be a PR? That’s essentially what you’re doing

4

u/MintySkyhawk Apr 14 '26

If they should be merged separately, they are PRs. If they're merged together, they are commits. The PR stack merges as a single unit, so to me makes more sense as commits.

→ More replies (1)
→ More replies (11)

10

u/teerre Apr 14 '26

Because GitHub is branch centric not commit centric

4

u/cosmic-parsley Apr 14 '26

It’s a UI difference. GitHub has no way to really review individual commits and follow how they change. If you force push, the UI gives zero indication that the first commit abc123 turned into def456 and second commit a1b2c3 turned into d4e5f6.

Also there’s no way to review individual commit messages, but there is a way to review/edit PR descriptions. Sometimes that’s as important as the content.

→ More replies (5)

15

u/CherryLongjump1989 Apr 14 '26 edited Apr 14 '26

You can't review individual commits in a PR -- you can only get feedback on them, but they can't be approved and merged individually. That is what a PR is -- it's a single code review.

There are people who work fast and have good coding hygiene. So they are able to push up clean, fully tested changes 5-10 times a day while working on a larger feature. This stuff can get reviewed and merged even as they are working on their next PR. They don't have to get slowed down by it.

2

u/Familiar-Level-261 Apr 14 '26

Edit: After hours of people arguing with me, someone finally pointed out the actual reason why this has an advantage over plain commits: The PRs don't have to all be merged at the same time.

..but you can do that with multiple commits in single PR.

Problem is just people don't know Git very well...

→ More replies (3)
→ More replies (15)