gitgit-rebasefeature-branch

Change parent branch to feature branch


I was working on a feature branch in this structure:

a -- b -- c -- d           <-- master
     \     \
      \     e -- f         <-- feature
       \
        g                  <-- new_parent

But I need to switch my branches to be in this way:

a -- b -- c -- d           <-- master
      \
       g                   <-- new_parent
        \
         e -- f            <-- feature

Note that my feature branch comes from master that is ahead of new_parent because I rebased it from master and new_parent will be rebased into master once all the work is done in the feature branch and rebased to new_parent.

I'm not that familiar with git, and I don't want to mess my repo, I read about git rebase onto command, but I'm not sure if the below command will do what I'm trying to do.

git rebase --onto new_parent feature master

Solution

  • You want git rebase --onto new_parent master feature

    Command format from the man page:

    git rebase [--onto <newbase>] [<upstream> [<branch>]]
    

    new_parent is newbase i.e. the point you want to apply your changes to.

    master is upstream i.e. the point from which your changes currently start.

    feature is obviously branch i.e. the branch on which your changes can be found.