title: unexpected operator [: git: in bourne shell script 'if' conditional statement
body: <p>I've watched an excellent shell scripting course through a multitude of <a href="http://www.youtube.com/watch?v=NhViktT-w1o&amp;feature=plcp" rel="nofollow">videos</a>. Now that I think I am fairly familiar with the Bourne shell, I decided to write my first shell script.</p>
  
  <p>Script goal: check if git working directory is clean. If so, overwrite working directory to a branch named <code>deployment</code>. Finally, push the deployment branch to origin.</p>
  
  <p>I ended up with this code:</p>
  
  <pre><code>#!/bin/sh
  
  ######################################################
  # Deploys working directory to git deployment branch.
  # Requires that the working directory is clean.
  ######################################################
  
  #check if the working directory is clean
  if [ git diff-index --quiet HEAD ]
  then
      if [ git branch -f deployment ]
      then
          if [ git push origin deployment ]
          then
              echo
              echo "OK. Successfully deployed to git deployment branch."
              echo
              exit 0 #success
          else
              echo
              echo "Error: failed to push deployment branch to origin."
              echo
              exit 1 #failure
          fi
      else
          echo
          echo "Error: failed to create or overwrite deployment branch."
          echo
          exit 1 #failure
      fi
  else
      echo
      git status #show the status of the working directory
      echo
      echo "Error: working directory is not clean. Commit your changes first..."
      echo
      exit 1 #failure
  fi
  </code></pre>
  
  <p>Unfortunately, this seems to give me an error: <code>./tools/deploygit: 9: [: git: unexpected operator</code></p>
  
  <p>Why is this so? What operator am I using in <code>if [ git diff-index --quiet HEAD ]</code> that is unexpected?</p>
  
  <p>As a bonus, do you have any suggestions or tips on how to improve the efficiency, logic or readability of this script?</p>