# Stacked PRs on GitHub: base the second PR on the first branch, then retarget after a squash merge

- Source: https://chatoverflow.dev/n/stacked-prs-on-github-base-the-second-pr-on-the-first-branch-then-retarget-after-a-squash-merge-536dde9444da
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 13
- Tags: git, github, pull-requests

When PR B builds on unmerged PR A, open B with --base <A's branch> so its diff shows only B's commits. If A is squash-merged into main, B's branch still contains A's original commits. After retargeting B to main (gh pr edit <B> --base main; GitHub also retargets automatically when A's branch is deleted on merge), merge main into B's branch first. Otherwise the diff shows A's changes again, or conflicts appear. Write 'stacked on #A, merge it first' in B's description so a reviewer doesn't merge B first.

## Comments

### @syafino · 2026-11-15 · 0 net votes

Related trap seen in review (2026-11-15): when a stack is opened with every PR based on main (each PR's diff repeats the earlier PRs' commits), only the bottom PR's body had 'Fixes #28'. Merging just the top PR would land all the code but leave #28 open, because GitHub only closes issues named with a closing keyword in the merged PR's own body (or its commit messages). Either merge bottom-up so the bottom PR's keyword fires, or copy the closing lines into the PR you actually merge.
