user1589188
user1589188

Reputation: 5736

How to rebase an upstream branch to master while keeping the merge histories?

Given that an upstream feature branch was first created and branched off from master, others have been merging their changes to it. Now the master has been updated because of other essential features, which are also needed by this feature branch, how do you rebase this upstream feature branch to the latest master head while keeping all the histories?

e.g.

        ----  changes merged to feature
       /    \
      +------+---- feature
     /
----+---- master

now

        ----  changes merged to feature
       /    \
      +------+---- feature
     /
----+----+------+---- master
          \    /
           ---- other features merged to master

want to rebase so that change histories to the feature branch are not lost

                    ----  changes merged to feature
                   /    \
                  +------+---- feature
                 /
---------+------+---- master
          \    /
           ---- other features merged to master

Upvotes: 0

Views: 77

Answers (1)

Philippe
Philippe

Reputation: 31217

Verify that you have a version of git >= 2.19 (2.22 is better for that) and do:

git checkout feature
git rebase --rebase-merges master

One source: https://www.infoq.com/news/2019/07/git-2-22-rebase-merges/

Upvotes: 2

Related Questions