title: Git checkout to external work tree and remove deleted files
body: <p>We want to use Git to deploy code on our webserver. Therefore, we have a initialized a bare repository on our production server. Whenever we release a new version, we perform a git checkout into the DocumentRoot of the website:</p>
  
  <pre><code>git --work-tree=/path/to/webroot/ checkout -f master
  </code></pre>
  
  <p>In the subdirectories of <code>webroot</code>, there are several files which are not tracked by Git (Cache files, user-uploaded files etc.). These must of course not be deleted by Git when performing the checkout (and this part works fine so far).</p>
  
  <p>However, Git also does not delete files which were previously tracked, but have been removed in the meantime (e.g. they were deleted in the development process because they are no longer needed). Such files currently survive the <code>checkout</code> process, leading to a steadily increasing number of "dead" files. Is there a way to make Git delete such files when performing the <code>checkout</code>?</p>
  
  <p><strong>EDIT - steps to reproduce:</strong></p>
  
  <pre><code># create dirs and repos
  cd /base/path
  mkdir repo.git
  mkdir target
  cd repo.git &amp;&amp; git init
  
  # create, add and commit two files
  touch test1.txt
  touch test2.txt
  git add test1.txt test2.txt
  git commit -m testcommit
  
  # checkout to target directory
  git --work-tree=../target checkout master -f
  # target directory now contains both files
  
  # remove one file from file system and git repo, commit
  rm test2.txt
  git rm test2.txt
  git commit -m deletecommit
  
  # checkout to target again
  git --work-tree=../target checkout master -f
  # target still contains both files
  </code></pre>