Skip to content

Instantly share code, notes, and snippets.

@ekilah
Last active April 11, 2025 18:25
Show Gist options
  • Save ekilah/4c93cf2e7ad614b5f9541c589f415c18 to your computer and use it in GitHub Desktop.
Save ekilah/4c93cf2e7ad614b5f9541c589f415c18 to your computer and use it in GitHub Desktop.
rebasing stacked PRs with --onto

TLDR:

git rebase --onto newBase oldBase thingToRebase

if you had this:

                X---Y---Z sub-feature
               /
          E---F---G---H  feature
         /
    A---B---C---D  master

but then a git rebase master on feature produced this

                X---Y---Z sub-feature
               /
          E---F---G---H  feature(previous)
         /
    A---B---C---D  master
                 \
                  E'---F'---G'---H'  feature(new)

sub-feature is now based on an outdated version of feature and you need to rebase it to make H' its new base.

to fix sub-feature, run this from sub-feature:

git rebase --onto H' F sub-feature

to end up with this:

                                     X---Y---Z sub-feature
                                    /
                   E'---F'---G'---H'  feature
                 /
    A---B---C---D  master

source: http://voidcanvas.com/how-to-rebase-a-branch-when-the-parent-is-rebased-with-another/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment