title: Create new git repo from already existing repo's subdirectory
body: <p>I want to create a separate repo from an already existing repo's subfolder.</p>
  
  <p><a href="https://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository">Detach (move) subdirectory into separate Git repository</a> shows exactly that. BUT, I can't get a clean repo with it. I end up with two problems with the new repo:</p>
  
  <ol>
  <li>The history seems duplicated;</li>
  <li>I can't keep the branches history.</li>
  </ol>
  
  <p>Here is what I did:</p>
  
  <pre><code>$ git clone ssh://.../repo.git
  $ cd repo
  $ git filter-branch --subdirectory-filter subdirectory HEAD -- --all
  $ git reset --hard
  $ git gc --aggressive
  $ git prune
  </code></pre>
  
  <p>After this, it seems I have the original history of the repo AND the new history. I type "git log <strong>--all</strong> --graph" (or gitk --all) I see, as the first commit, the initial commit of the first repo. The graph then shows the original repo's full history until the last commit. Then, I have a SECOND history on top of the first one showing the history of only the subfolder I want. But in that part of the history I only have "master" and no branches/merges.</p>
  
  <p>"git log", gitk or gitg all show the "flatten" history only: they don't show the initial repo's history before the the subfolder's flatten history.</p>
  
  <p>I tried using just the "filter-branch" command, cloning the resulting repo (with --no-hardlinks), using:</p>
  
  <pre><code>$ git filter-branch --subdirectory-filter subdirectory -- --all
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>$ git filter-branch --subdirectory-filter subdirectory HEAD -- --all
  </code></pre>
  
  <p>But with the same result.</p>
  
  <p>Am I am doing something wrong or git is broken? I'm really out of ideas... Using git 1.7.6. Thanks.</p>
  
  <p>EDIT: I think the problem might come from the fact that merge commits are ignored by filter-branch, thus giving a flat history with no branches or merges...</p>