3

So I have a complex local branch structure: my main working local branch, and two other branches off of it. There was a new change in master that I want in my branches. What is the best way to propagate it to all of my branches? Is rebasing possible?

A---E---M  master 
     \ 
      F---G---H  local_branch_main
          |\ 
          | I---J  local_subbranch_1
           \K---L  local_subbranch_2

Ideally, I'd want to just move all the branches to reference off of the new master commit (there are no conflicts):

A---E---M  master 
         \ 
          F---G---H  local_branch_main
              |\ 
              | I---J  local_subbranch_1
               \K---L  local_subbranch_2
eengineer
  • 177
  • 2
  • 9
  • Without knowing what you branch update strategy is or how many developers have local copies of those branches it is impossible to even guess. – Andrew C Oct 23 '14 at 19:27
  • @AndrewC: This is all local, with the exception of commit M. But I can make everyone accept whatever history I come up with. – eengineer Oct 23 '14 at 20:15
  • @Tonio, that looks promising but I get the following error: fatal: no such branch: * error: could not apply C... – eengineer Oct 23 '14 at 20:19
  • In that case just start with main and rebase, then do the two sub-branches. `git rebase --onto SHA` – Andrew C Oct 23 '14 at 20:19
  • If I do that, I get the subbranches pointing to the old non-rebased commits as in the link Tonio suggested. – eengineer Oct 23 '14 at 20:51

1 Answers1

0

You can do it this way

First do

git checkout local_branch_main
git rebase master

If you are lucky and you don't have any conflicts your repository will now look like this:

A---E---M  master 
    \    \ 
     \    F'---G---H  local_branch_main
      F
      |\ 
      | I---J  local_subbranch_1
       \K---L  local_subbranch_2

Now here comes the interessting part. As you can see the commit F and F' contains the same changes (if there were no conflicts), but F' has another parent commit and another commit id. I make this visible by naming it F'.

So now you can switch to branch local_subbranch_1 and rebase it on F'

git checkout local_subbranch_1
git rebase F'

of course you must replase F' with the commit id of F'

Now your repository looks like this

   A---E---M  master 
       \    \ 
        \    F'---G---H  local_branch_main
        F     \ 
         \     I---J  local_subbranch_1
          \
           K---L  local_subbranch_2

Finally you can checkout local_subbranch_2 and rebase it on F' and your repository will look like

   A---E---M  master 
            \ 
             F'---G---H  local_branch_main
             |\ 
             | I---J  local_subbranch_1
             \
               K---L  local_subbranch_2

I have created a demo repository that you can download here. You can replay the steps above on it.

René Link
  • 48,224
  • 13
  • 108
  • 140