title: JGit: Checkout a remote branch
body: <p>I'm using JGit to checkout a remote tracking branch.</p>
  
  <pre class="lang-java prettyprint-override"><code>Git binrepository = cloneCmd.call()
  
  CheckoutCommand checkoutCmd = binrepository.checkout();
  checkoutCmd.setName( "origin/" + branchName);
  checkoutCmd.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK );
  checkoutCmd.setStartPoint( "origin/" + branchName );
  
  Ref ref = checkoutCmd.call();
  </code></pre>
  
  <p>The files are checked out, but the HEAD is not pointing to the branch.
  Following is the <code>git status</code> output,</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ git status
  # Not currently on any branch.
  nothing to commit (working directory clean)
  </code></pre>
  
  <p>The same operation can be performed in git command line, easily and it works,</p>
  
  <pre class="lang-sh prettyprint-override"><code>git checkout -t origin/mybranch
  </code></pre>
  
  <p>How to do this JGit?</p>