title: When using git commands in batch script, how to fail on error?
body: <p>Below is the batch script in which I am executing a set of git operations, how I can fail on a git error like on git checkout "Branch already exits"</p>
  
  <p>```</p>
  
  <pre><code>REM arg 1 = branch to copy
  REM arg 2 = branch in which copy will be merged
  set arg1=%1%
  set arg2=%2%
  echo copying %arg1% to %arg2%
  echo "check out as tmp "+%arg1%
  set ret = git checkout -b tmp %arg1%
  echo %ret%
  set ret = git checkout -b tmp %arg1%
  echo %ret%
  exit 0
  REM emitted code for brevity 
  </code></pre>
  
  <p>```
  output : </p>
  
  <pre><code>c:\my-project&gt;c:\bat\git-copy-branch.bat master my-git-branch
  
  c:\my-project&gt;git checkout -b tmp master
  fatal: A branch named 'tmp' already exists.
  
  c:\my-project&gt;git checkout -b tmp master
  fatal: A branch named 'tmp' already exists.
  
  c:\my-project&gt;git checkout -b tmp master
  fatal: A branch named 'tmp' already exists.
  </code></pre>