title: How do I rebase a chain of local git branches?
body: <p>Suppose I have a chain of local git branches, like this:</p>
  
  <pre><code>       master    branch1   branch2
            |         |         |
  o----o----o----A----B----C----D
  </code></pre>
  
  <p>I pull in an upstream change onto the master branch:</p>
  
  <pre><code>              branch1   branch2
                   |         |
              A----B----C----D
             /
  o----o----o----o
                 |
              master
  </code></pre>
  
  <p>Now I rebase branch1, giving me this:</p>
  
  <pre><code>                        branch2
                             |
              A----B----C----D
             /          
  o----o----o----o----A'---B'
                 |         |
              master    branch1
  </code></pre>
  
  <p>Note that because of rebasing branch1, commits A and B have been rewritten as A' and B'.</p>
  
  <p>Here's my problem: now I want to rebase branch2. The obvious syntax is <code>git rebase branch1 branch2</code>, but that definitely does not work. What I want it to do is just reapply C and D on top of branch1, but instead it tries to reconcile A and A' and it considers them conflicting.</p>
  
  <p>This does work:</p>
  
  <pre><code>git rebase --onto branch1 branch2^^ branch2
  </code></pre>
  
  <p>This assumes I know that branch2 has exactly 2 commits beyond the previous branch1 ref.</p>
  
  <p>Since <code>git rebase --onto</code> works, is there a 1-line git command that will rebase branch2 on top of a newly-rebased branch1, in a way that I don't have to know exactly how many commits were part of branch2? (I want to specify some magic ref instead of branch2^^ for the middle argument.)</p>
  
  <p>Or is there some other approach I'm overlooking?</p>
  
  <p>I would be most interested in a solution that scales well to extreme cases, not just two branches - suppose I've got something more like 5 local branches, all chained on one another, and I want to rebase all of them together.</p>