title: git archive export with submodules (git archive all / recursive)
body: <p>I have a website directory versioned with git. I use submodules for required libraries like Twitter Bootstrap, colorbox and lessjs because I should not track the sourcecode but only the version of their code I use.</p>
  
  <p>Now I want to deploy the project and therefore I need the submodule code too.
  By using <code>git archive</code> I don't get the source files/code from the submodules.</p>
  
  <p>The following three approaches TRY to achieve what I want but dont't work:
  <strong>1st approach</strong></p>
  
  <pre><code>#!/bin/sh
  
  export revision="$1"
  
  export GIT_INDEX_FILE=".git/tmpindex"
  rm -f "$GIT_INDEX_FILE"
  
  git read-tree $revision
  
  export up="$(pwd)"
  
  read_one_level () {
          export GIT_ALTERNATE_OBJECT_DIRECTORIES="$GIT_ALTERNATE_OBJECT_DIRECTORIES":$(
              git submodule foreach 'echo "$up/$path/.git/objects"' |
              grep -E -v '^(Entering|No submodule mapping found)' |
              tr '\n' : |
              sed 's/:$//'
          )
  
          git submodule foreach '
                  cd "$up"
                  subcommit=$(git rev-parse :"$path")
                  git rm --cached "$path"
                  git read-tree -i --prefix="$path/" $subcommit
          ' &gt;/dev/null
  }
  
  while git ls-files -s | grep -q ^160000; do
      read_one_level
  done
  
  git archive --format=tar $(git write-tree)
  
  rm -f "$GIT_INDEX_FILE" 
  </code></pre>
  
  <p>Thomas Rast in <a href="http://git.661346.n2.nabble.com/Running-git-archive-recursively-over-submodules-td4577012.html">http://git.661346.n2.nabble.com/Running-git-archive-recursively-over-submodules-td4577012.html</a></p>
  
  <p>This gives me errors both on Windows as in Linux that there are no objects files found.</p>
  
  <p><strong>2nd approach</strong>
  <a href="https://github.com/meitar/git-archive-all.sh">https://github.com/meitar/git-archive-all.sh</a></p>
  
  <p>Complains about mktemp not found on Windows. And correcting calls to <code>git archive</code> (from <code>git-archive</code>) does not give submodules in the tar ...:(</p>
  
  <p><strong>3rd approach</strong>
  <a href="https://github.com/Kentzo/git-archive-all">https://github.com/Kentzo/git-archive-all</a></p>
  
  <p>Is outdated from my point of view by not being compatible to latest python 3.3 and still not fully working by using 2.7 because samefile complains.</p>
  
  <p>So my question is now:
  Is there any recent way/approach to deal with exporting/archive a git project including submodules?</p>
  
  <p>Or should I check subtrees for this workflow?</p>
  
  <p>Thanks in advance</p>