Search code examples
gitrebase

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


While developing a feat branch based on the develop branch, the develop branch has been ‘frozen’, that is it has been merged into the staging branch. Now I would like to rebase feat onto staging because feat should be merged into staging before staging ‘goes into production’ next week, that is before staging is merged into the main branch.

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?


Solution

  • 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.)