title: Reuse GIT_WORK_TREE in post-receive hook to rm a few files
body: <p>I've used this 'tutorial' to set up a DSP environment: <a href="http://toroid.org/ams/git-website-howto" rel="noreferrer">http://toroid.org/ams/git-website-howto</a> (Yes, I don't have a T).</p>
  
  <p>My workflow is very easy:</p>
  
  <ol>
  <li>Develop locally (<strong>D</strong>)</li>
  <li>Commit a few things</li>
  <li>Commit more things</li>
  <li>Push to Staging (and Github) (<strong>S</strong>)</li>
  <li>Test new code on Staging</li>
  <li>Push to Production (<strong>P</strong>)</li>
  </ol>
  
  <p>My code contains CSS files that are minified by my code and then saved to 1 file: <code>all.css</code>. Locally, I've turned that option off, so I don't have to manually remove <code>all.css</code> all the time every time I change my CSS. On both Staging and Production, they should cache as soon as possible (so create <code>all.css</code> from the separate CSS files).</p>
  
  <p>The problem is every time I push, I have to remove <code>all.css</code> (and <code>all.js</code> -- same exact story) to see the changes (and properly test).</p>
  
  <p>From the tutorial I made a <code>post-receive</code> hook that checks out the changes into a certain folder (where Apache reads the code).</p>
  
  <p>My current <code>post-receive</code> hook:</p>
  
  <pre><code>#!/bin/sh
  GIT_WORK_TREE=/var/www/www.example.org git checkout -f
  </code></pre>
  
  <p>I want to reuse <code>$GIT_WORK_TREE</code> to remove two files within <code>$GIT_WORK_TREE</code> (being <code>www/all.css</code> and <code>www/all.js</code>), but I can't... There's no var $GIT_WORK_TREE on the next line.</p>
  
  <p>So I changed it to this, but I don't like that, especially if I want to do more with it in the future:</p>
  
  <pre><code>#!/bin/sh
  GIT_WORK_TREE=/var/www/www.example.org git checkout -f
  rm /var/www/www.example.org/www/all.css
  rm /var/www/www.example.org/www/all.js
  </code></pre>
  
  <p><code>$GIT_WORK_TREE</code> is NOT reused like this.</p>
  
  <p><strong>Things I've tried that don't work:</strong></p>
  
  <pre><code>GIT_WORK_TREE=/var/www/www.example.org git checkout -f
  rm $GIT_WORK_TREE/www/all.css
  rm $GIT_WORK_TREE/www/all.js
  </code></pre>
  
  <blockquote>
    <p>rm: file doesn't exist etc (/www/all.css) (<code>$GIT_WORK_TREE</code> is empty)</p>
  </blockquote>
  
  <pre><code>GIT_WORK_TREE=/var/www/www.example.org
  git checkout -f
  </code></pre>
  
  <blockquote>
    <p>fatal: this operation must be run in a work tree</p>
  </blockquote>
  
  <pre><code>GIT_WORK_TREE=/var/www/www.example.org
  cd $GIT_WORK_TREE
  git checkout -f
  </code></pre>
  
  <blockquote>
    <p>fatal: Not in a git repository (or any .....)</p>
  </blockquote>
  
  <p>I guess my problem is as much with how Bash works as it is with how GIT works =)</p>