title: How to programmatically determine the current checked out Git branch
body: <p><strong>In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine which Git branch is currently checked out in a working directory?</strong></p>
  
  <p>One use of this technique would be automatically labeling a release (like <code>svnversion</code> would do with Subversion).</p>
  
  <p>Please also see my related question: <a href="https://stackoverflow.com/questions/1593188/how-to-programmatically-determine-whether-the-git-checkout-is-a-tag-and-if-so-wh">How to programmatically determine whether a Git checkout is a tag, and if so what is the tag name?</a></p>