Rebase and move parent branches along


TLDR I want the parent branches (in a linear branch) to move along with the new commits during a rebase.

Initial setup: multiple feature branches (on top of each other) each one waiting to be merged into master

A--B--C--D <-master
       ^     ^     ^     ^
       |     |     |     feature_d
       |     |     feature_c
       |     feature_b

A review is made, a new commit M is added to feature_a, then it is merged into master:

A--B--C--D--N <-master
   \       /
    E--F--M <- feature_a
           ^     ^     ^
           |     |     feature_d
           |     feature_c

It’s here where I want to do the rebase.

Desired result: rebase feature_d to master and move all parent branches along:

A--B--C--D--N <-master
   \       / \
    E--F--M   G'--H'--I'--J'--K'--L'
                  ^       ^       ^
                  |       |       feature_d
                  |       feature_c

The way I know how to do this is “manual”, i.e. normal rebase of feature_d followed by moving each branch pointer:

git checkout feature_d
git rebase master
git branch -f feature_b H'
git branch -f feature_c J'

This requires manually searching and referencing the new commits by their sha. It involves extra attention and is error prone. I am hoping for an automated process, something like this:

git checkout feature_d
git rebase master --magic-option-move-branches-to-new-commits


This solution it’s not one magic command, but it it does avoid manual naming of commits. Rebase each branch on top of it’s parent branch, starting with the oldest one:

git checkout feature_b
git rebase master

git checkout feature_c
git rebase feature_b

git checkout feature_d
git rebase feature_c

I wasn’t expected this to work. Here is the explanation why it works: Git rebase skipping identical commits

Answered By – bolov

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published