How to rebase a branch onto another branch than the upstream branch?

59 Views Asked by At

While developing a feat branch based on the develop branch, the develop branch has been frozen, that is merged into the staging branch. So now I would like to rebase my feat branch onto staging.

Initial version history:

  D---E feat
 /
A---B---C develop
     \
  F---G---H staging

Final version history (what I want to get):

A---B---C develop
     \
  F---G---H staging
           \
            D---E feat

Final version history (what I will get with the git rebase develop feat command):

          D---E feat
         /
A---B---C develop
     \
  F---G---H staging

Which git command will set the initial version history into the desired state?

2

There are 2 best solutions below

2
matt On BEST ANSWER

You would say

git rebase --onto staging develop feat

in order to get "what I want to get".

(This kind of move comes with a risk of merge conflicts but there's nothing you can do about that; any way of performing this move would entail the same risk.)

1
Bryan On

First make sure you're on the feature branch: git checkout feat

If you need to, use git pull to update your branches.

Then use this command to rebase to the staging branch: git rebase staging

I hope this helps!