title: GIT & Ruby: How can I unset the GIT_DIR variable from inside a ruby script?
body: <p>I've written a very simple 'deploy' script running as my <code>post-update</code> hook inside my bare git repo.</p>
  
  <p>The variables are as follows</p>
  
  <pre><code>live domain         = ~/mydomain.com
  staging domain      = ~/stage.mydomain.com
  git repo location   = ~/git.mydomain.com/thisrepo.git (bare)
  
  core                = ~/git.mydomain.com/thisrepo.git
  core                == added remote into each live &amp; stage gits
  </code></pre>
  
  <p>both <code>live</code> &amp; <code>stage</code> have initialized git repos (non-bare) and I have added my bare repo as a remote to each of them (named <code>core</code>) so that <code>git pull core stage</code> or <code>git pull core live</code> would pull the updated files from the respective <code>branch</code> of the <code>core</code> repo.</p>
  
  <p>The script is as follows:</p>
  
  <pre><code>#!/usr/bin/env ruby
  
  # Loop over each passed in argument
  ARGV.each do |branch|
  
    # If it matches the stage then 'update' the staging files
    if branch == "refs/heads/stage"
  
      puts ""
      puts "Looks like the staging branch was updated."
      puts "Running a tree checkout now…"
      puts ""
      `cd ~/stage.mydomain.com`
      `unset GIT_DIR` # &lt;= breaks!
      `git pull core stage`
      puts ""
      puts "Tree pull completed on staging branch."
      puts ""
  
    # If it's a live site update, update those files
    elsif branch == "refs/heads/live"
  
      puts ""
      puts "Looks like the live branch was updated."
      puts "Running a tree checkout now…"
      puts ""
      `cd ~/mydomain.com`
      `unset GIT_DIR` # &lt;= breaks!
      `git pull core live`
      puts ""
      puts "Tree checkout completed on live branch."
      puts ""
  
    end
  
  end
  </code></pre>
  
  <p>I have tried adapting the 'updating' of files from <a href="http://joemaller.com/990/a-web-focused-git-workflow/" rel="noreferrer" title="A web-focused Git workflow">this bash script here</a> which uses the <code>unset GIT_DIR</code> to run the next git command <code>git pull core stage</code> for example. <code>core</code> is the added <code>remote</code> of my <code>bare</code> repo in a different folder on the server.</p>
  
  <p>However when executing the script above I'm getting the following errors:</p>
  
  <pre><code>remote: hooks/post-update:35: command not found: unset GIT_DIR        
  remote: fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.        
  </code></pre>
  
  <p>Is there any way to do the same thing as <code>unset GIT_DIR</code> in a bash script within my ruby script?</p>
  
  <p>Many thanks,</p>
  
  <p>Jannis</p>