title: Git merge different repositories which are basically the same
body: <h1>Problem</h1>
  
  <p>I have two different repositories which are basically the same. Lets name one <code>RepoA</code> and the other <code>RepoB</code>.</p>
  
  <p><code>RepoA</code> is the <em>first</em> repository which has the following structure:</p>
  
  <ul>
  <li><code>FolderA</code>
  
  <ul>
  <li><code>2018</code></li>
  </ul></li>
  <li><code>FolderB</code>
  
  <ul>
  <li><code>2018</code></li>
  </ul></li>
  </ul>
  
  <p><code>RepoB</code> is the <em>second</em> repository. The first commit contains all files of the last commit of <code>RepoB</code>. Therefore the first commit is basically a copy, but it contains the following structure:</p>
  
  <ul>
  <li><code>FolderA</code>
  
  <ul>
  <li><code>2019</code></li>
  </ul></li>
  <li><code>FolderB</code>
  
  <ul>
  <li><code>2019</code></li>
  </ul></li>
  </ul>
  
  <p>So all the content from <code>RepoA/FolderA/2018/</code> is now in <code>RepoB/FolderA/2019/</code> plus some new changes which are commited in <code>RepoB</code>.</p>
  
  <h2>Goal</h2>
  
  <p>I came new into the project and want to merge both of the repositories to have access to the history of the file (<code>git log</code> and so on).</p>
  
  <p>I want the following structure: </p>
  
  <ul>
  <li><code>FolderA</code></li>
  <li><code>FolderB</code></li>
  </ul>
  
  <h1>Approach</h1>
  
  <ol>
  <li>In <code>RepoA</code> I moved all files from <code>FolderA/2018</code> to <code>FolderA</code> and deleted <code>FolderA</code> (<em>same for <code>FolderB</code></em>)</li>
  <li>I cherry picked the initial commit from <code>RepoB</code> into <code>RepoA</code> and moved the files on directory up (as described in the previous point)</li>
  <li>I extracted the following commits in <code>RepoB</code> as patch and modified all paths with search and replace</li>
  <li>I applied the patch via <code>git am &lt; patchfile</code></li>
  </ol>
  
  <h2>Problem</h2>
  
  <p>Because of the patch the branches are removed and the history becomes linear. Therefore I run into problems when there is a commit followed by a merge which resolves a merge conflict which is introduced by the commit.</p>