title: Reparent a git commit to have two parents, consolidating a number of branches, and preserving future merge history
body: <p>I created a private git repository for a project for a while back, and developed a pattern of creating a maintenance branch for each major version release. </p>
  
  <p>A few months down the line in the project, I now have a number of branches for old versions, which are no longer under any form of support. I've realised that this is a messy way to handle  the problem. As a tidier alternative, I'd like to maintain a development branch and a release branch, with tags for the individual versions instead.</p>
  
  <p>I'd ideally like to convert the current repository to this new format. I want to preserve as much as the commit history as possible in terms of the relationship between release commits and commits on master, but I want to convert all of the release branches into one single release branch.</p>
  
  <p><img src="https://i.stack.imgur.com/ojSNL.png" alt="desired repository layout - before and after"></p>
  
  <p>The repository is only used by me, so I could paste the contents of a branch onto the end of another branch quite easily with <code>git rebase --onto</code> -- <strong>I'm not concerned about preserving the exact commit hashes here.</strong> </p>
  
  <p>What I am concerned about preserving is the merge history with the master branch. I'd like to reparent the root commit of each branch so that is based on both the tip of the previous branch, and the commit where it originally branched from master -- turn it into a merge commit.</p>
  
  <p>I'd then like to preserve a number of other merges between master and that branch, which happened further up the chain. </p>
  
  <p>I tried something along the lines of <code>git rebase --onto branchB-divergence...branchA-tip branchB</code> (and a couple of variants, including trying -m and -i, while trawling through the docs)</p>
  
  <p>The result was either accidentally duplicating a lot of the commits on master, and losing the merge history, or constantly getting merge conflicts which needed resolving.</p>
  
  <p>Is what I'm trying to achieve even possible? What sort of procedure would I follow to reparent a series of commits like this?</p>