title: JGit create new local branch and push to remote (branch does not exist on remote)
body: <p>I'm working on an ANT task that calls some java that uses JGit to create a new branch on a git repository and push it to remote. I'm using JGit 2.1.0.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>CreateBranchCommand bcc;
  CheckoutCommand checkout;
  Git git;
  
  try {
      Repository repo = new FileRepositoryBuilder().readEnvironment().findGitDir(src).build();
      git = new Git(repo);
  
      bcc = git.branchCreate();
      checkout = git.checkout();
  } catch (IOException e) {
      throw new BuildException("Could not access repository " + src, e);
  }
  
  try {
          bcc.setName(branch)
              .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
              .setStartPoint("origin/" + branch)
              .setForce(force)
              .call();
  
          checkout.setName(branch);
          checkout.call();
  }
  } catch (Exception e) {
      throw new BuildException("Could not checkout repository " + src, e);
  }
  </code></pre>
  
  <p>The <em>src</em> variable is set to the path of the git repo (which has already been cloned). 
  The <em>branch</em> variable is set to: <strong>release_2_0_2</strong>
  The <em>force</em> variable is set to: <strong>true</strong> or <strong>false</strong> (with both I have this issue).</p>
  
  <p>There is a separate ANT task afterward to do the push.</p>
  
  <p>When running the above code an exception is caught in the 2nd catch:</p>
  
  <pre><code>org.eclipse.jgit.api.errors.RefNotFoundException: Ref origin/release_2_0_2 can not be resolved
  </code></pre>
  
  <p>The issue seems to be with <code>setStartPoint("origin/" + branch)</code> If I hard code this to "origin/master" it works. The new branch is created. I'm simply trying to create a new branch locally and then push it to the remote. I was using <a href="https://stackoverflow.com/a/12928374/1860867">https://stackoverflow.com/a/12928374/1860867</a> as an example.</p>
  
  <p>Maybe I'm misunderstanding how the CreateBranchCommand should be used, all the examples I've seen are setting the startpoint to <code>"origin/" + branch</code>.
  Any suggestions/clarification would be helpful.</p>