title: Git: how to copy only the versioned files from a subdirectory?
body: <h2>Problem</h2>
  
  <p>I have a git repo with two subdirectories under the root <code>:/a</code> and <code>:/b</code>, and I want to copy all <em>versioned</em> files from <code>:/a</code> into <code>:/a-copy</code>.</p>
  
  <p>Essentially, I'd like to do</p>
  
  <pre><code>git mv a a-copy
  </code></pre>
  
  <p>without actually moving <code>a</code>.</p>
  
  <h2>More Details</h2>
  
  <p>There are also many non-versioned files in <code>:/a</code>, and I don't want to delete them, so I can't simply do</p>
  
  <pre><code>git clean -df a
  cp -r a a-copy
  </code></pre>
  
  <p>The best workaround I've found (on Linux) is</p>
  
  <pre><code>mkdir a-copy
  cd a
  git ls-files -z | xargs -0 -i cp --parents {} ../a-copy
  </code></pre>
  
  <p>but I hope there is a simpler way.</p>
  
  <h2>Is This Question a Duplicate of "<a href="https://stackoverflow.com/questions/160608/do-a-git-export-like-svn-export">Do a “git export” (like “svn export”)?</a>"?</h2>
  
  <p><a href="https://stackoverflow.com/questions/160608/do-a-git-export-like-svn-export">That question</a> is similar, but it only covers the case of copying/exporting the <strong>entire</strong> repo. I only want to copy <strong>part of</strong> the repo, i.e. the files under <code>:/a</code>, and not also the files under <code>:/b</code>. I read that question and its answers before posting this question. Now that I have an answer to my question, I see that the <code>git archive</code> based solutions to that other question also solve my problem here.</p>