title: Shell script to check if specified Git branch exists?
body: <p>I need to create a Git branch using shell script, but since the branch may exist, I need to be aware of that. Currently I'm using:</p>
  
  <pre><code>if [ `git branch | grep $branch_name` ]
  then
      echo "Branch named $branch_name already exists"
  else
      echo "Branch named $branch_name does not exist"
  fi
  </code></pre>
  
  <p>But the problem is the <code>grep</code> command finds branch name without matching the exact name, that is, if I <code>grep name</code> then branch with a name <code>branch-name</code> would be matched.</p>
  
  <p>So is there a better way to do this?</p>
  
  <p>Thanks!</p>