title: How do I do git push with JGit?
body: <p>I'm trying to build a Java application that allows users to use Git based repositories. I was able to do this from the command-line, using the following commands:</p>
  
  <pre><code>git init
  &lt;create some files&gt;
  git add .
  git commit
  git remote add &lt;remote repository name&gt; &lt;remote repository URI&gt;
  git push -u &lt;remote repository name&gt; master
  </code></pre>
  
  <p>This allowed me to create, add and commit content to my local repository and push contents to the remote repository. 
  I am now trying to do the same thing in my Java code, using JGit. I was able to easily do git init, add and commit using JGit API. </p>
  
  <pre class="lang-java prettyprint-override"><code>Repository localRepo = new FileRepository(localPath);
  this.git = new Git(localRepo);        
  localRepo.create();  
  git.add().addFilePattern(".").call();
  git.commit().setMessage("test message").call();
  </code></pre>
  
  <p>Again, all of this works fine. I couldn't find any example or equivalent code for <code>git remote add</code> and <code>git push</code>. I did look at this <a href="https://stackoverflow.com/questions/6861881/jgit-cannot-find-a-tutorial-or-simple-example">SO question</a>. </p>
  
  <p><code>testPush()</code> fails with the error message <code>TransportException: origin not found</code>. In the other examples I've seen <a href="https://gist.github.com/2487157" rel="noreferrer">https://gist.github.com/2487157</a> do <code>git clone</code> <strong>before</strong> <code>git push</code> and I don't understand why that's necessary.</p>
  
  <p>Any pointers to how I can do this will be appreciated. </p>