Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebase feature branch onto another feature branch

I have two (private) feature branches that I'm working on.

a -- b -- c                  <-- Master      \     \       \     d -- e           <-- Branch1        \         f -- g               <-- Branch2 

After working on these branches a little while I've discovered that I need the changes from Branch2 in Branch1. I'd like to rebase the changes in Branch2 onto Branch1. I'd like to end up with the following:

a -- b -- c                  <-- Master            \             d -- e -- f -- g <-- Branch1 

I'm pretty sure I need to rebase the second branch onto the first, but I'm not entirely sure about the correct syntax and which branch I should have checked out.

Will this command produce the desired result?

(Branch1)$ git rebase --onto Branch1 Branch2 
like image 835
Arjen Avatar asked Feb 15 '13 11:02

Arjen


1 Answers

  1. Switch to Branch2

    git checkout Branch2 
  2. Apply the current (Branch2) changes on top of the Branch1 changes, staying in Branch2:

    git rebase Branch1 

Which would leave you with the desired result in Branch2:

a -- b -- c                      <-- Master            \             d -- e               <-- Branch1            \             d -- e -- f' -- g'   <-- Branch2 

You can delete Branch1.

like image 154
sasikt Avatar answered Oct 16 '22 09:10

sasikt