title: Platform-independent way of detecting if git is installed
body: <p>This is how I detect git in ruby:</p>
  
  <pre><code>`which git 2&gt;/dev/null` and $?.success?
  </code></pre>
  
  <p>However, this is not cross-platform. It fails on non-unix systems or those without the <code>which</code> command (although I'm not sure what those are).</p>
  
  <p>I need a way to detect git that satisfies these conditions:</p>
  
  <ol>
  <li>works reliably cross-platform, even on Windows</li>
  <li>doesn't output anything to $stdout or $stderr</li>
  <li>small amount of code</li>
  </ol>
  
  <hr>
  
  <p><strong>Update:</strong> the solution is to avoid using <code>which</code> altogether and to redirect output to <code>NUL</code> on Windows.</p>
  
  <pre><code>require 'rbconfig'
  void = RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null'
  system "git --version &gt;&gt;#{void} 2&gt;&amp;1"
  </code></pre>
  
  <p>The <code>system</code> command returns true on success and false on failure, saving us the trip to <code>$?.success?</code> which is needed when using backticks.</p>