Updating Stacked Pull Requests with git rebase --onto

Lobsters Hottest Tools

Summary

Explains how to use `git rebase --onto` to update stacked pull requests when the parent commit has been squashed or replaced.

<p><a href="https://lobste.rs/s/akc6h4/updating_stacked_pull_requests_with_git">Comments</a></p>
Original Article
View Cached Full Text

Cached at: 06/18/26, 10:07 PM

# Updating Stacked Pull Requests with git rebase --onto Source: [https://bd103.dev/blog/2026-06-18-git-rebase-onto/](https://bd103.dev/blog/2026-06-18-git-rebase-onto/) Sometimes I find myself in the situation where I have multiple pull requests that build off of each other\. ![TODO](https://bd103.dev/blog/2026-06-18-git-rebase-onto/original.png)Then, a reviewer asks me to squash*commit B*into*commit A*, creating a new*commit E*\. I do so, but now my second pull request is all messed up\! ![TODO](https://bd103.dev/blog/2026-06-18-git-rebase-onto/squashed.png)When Git created*commit E*, it didn't tell*commit B*'s children that their new parent should be*commit E*\. This means that*commit C*still thinks its parent is*commit B*\! ![TODO](https://bd103.dev/blog/2026-06-18-git-rebase-onto/commit-c-dark.png)![TODO](https://bd103.dev/blog/2026-06-18-git-rebase-onto/commit-c-light.png)While this behavior is a sensible default, in this scenario we don't want it\. We can tell*commit C*that its new parent is*commit E*by rebasing it with the following command: ``` # Make sure we're on the second PR's branch. git switch second-pr # Tell commit C that its new parent is E, not B. git rebase --onto E B ``` ![TODO](https://bd103.dev/blog/2026-06-18-git-rebase-onto/rebased.png)The general form of this command is`git rebase \-\-onto <newparent\> <oldparent\>`, and it's very useful when updating stacked pull requests where the parent commit has been replaced\. You don't need it if the base pull request only had new commits added, though, in which case you would use a normal`git rebase`without the`\-\-onto`option\. Once you do rebase your second pull request, take a look at the[`\-\-force\-with\-lease`](https://git-scm.com/docs/git-push#Documentation/git-push.txt---force-with-lease)option of`git push`to safely push your changes to the remote\. ![TODO](https://bd103.dev/blog/2026-06-18-git-rebase-onto/commit-f-dark.png)![TODO](https://bd103.dev/blog/2026-06-18-git-rebase-onto/commit-f-light.png)*Thank you to[sEver on Stack Overflow for the answer](https://stackoverflow.com/a/39081674)that inspired this article\!*

Similar Articles

spr: Stacked Pull Requests on GitHub

Lobsters Hottest

spr is a CLI tool that converts each commit on a Git branch into a separate pull request on GitHub, enabling stacked PRs without manual branch management.

Highlights from Git 2.54

Lobsters Hottest

Git 2.54 ships with a new experimental `git history` command that lets users reword or split commits without touching the working tree, plus 137 contributors’ worth of other improvements.

Using Changesets in a polyglot monorepo

Hacker News Top

A blog post explaining how to use the Changesets tool for versioning and changelog management in a polyglot monorepo spanning multiple programming languages, leveraging its GitHub Action for custom version and publish scripts.