title: How can I get the current git branch in gradle?
body: <p>I'm writing a task to deploy my application to the server. However, I'd like for this task to run only if my current git branch is the master branch.
  How can I get the current git branch?</p>
  
  <h3><code>gradle-git</code> approach:</h3>
  
  <p>I know there is a <a href="https://github.com/ajoberstar/gradle-git">gradle-git plugin</a> that has a method <code>getWorkingBranch()</code> under the task <code>GitBranchList</code>, but anytime I try to execute </p>
  
  <pre><code>task getBranchName(type: GitBranchList) {
     print getWorkingBranch().name
  }
  </code></pre>
  
  <p>I get a "Task has not executed yet" error. I looked at the <a href="https://github.com/ajoberstar/gradle-git/blob/master/src/main/groovy/org/ajoberstar/gradle/git/tasks/GitBranchList.java">source</a> and it throws that error when there is no branch set. Does that mean this method doesn't do quite what I think it does? That I need to set the branch somewhere?</p>