title: How do I list all commits without cloning a repository?
body: <p>Given a remote location, I would like to list all commits of that repository without having to clone it, using <a href="https://www.eclipse.org/jgit/" rel="nofollow noreferrer">JGit</a>.</p>
  
  <p>As far as I know, accessing commits is only possible by doing a <a href="http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/revwalk/RevWalk.html" rel="nofollow noreferrer"><code>RevWalk</code></a>. To obtain an object of this class, you need an object of <a href="http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/lib/Repository.html" rel="nofollow noreferrer"><code>Repository</code></a>. Now I tried creating a new, empty repository locally like so:</p>
  
  <pre><code>Git git = Git.init().setDirectory(localDir).call();
  </code></pre>
  
  <p>... and adding a remote location afterwards like so:</p>
  
  <pre><code>git.remoteAdd()
      .setName("origin");
      .setUri(new URIish(remoteLocationStr));
      .call();
  </code></pre>
  
  <p>However, when I try to start the <a href="http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/revwalk/RevWalk.html" rel="nofollow noreferrer"><code>RevWalk</code></a>, it is empty.</p>
  
  <pre><code>try (RevWalk revWalk = new RevWalk(git.getRepository())) {
      for( RevCommit commit : revWalk ) {
          //... nothing to iterate here
      }
  }
  </code></pre>
  
  <p>I assume this is due to the fact that I never did a <code>clone</code>, <code>pull</code> or similar to actually update the local file system with the necessary information.</p>
  
  <p>Is there any way to achieve this without having to clone the whole repository? Using <code>fetch</code> perhaps? (any tricks allowed)</p>
  
  <p><strong>Use Case</strong></p>
  
  <p>I need to sync cloud storage with the contents of a git repository. After having cloned and uploaded all files of the repository, it is deleted from the machine that performed the upload. Unless hooks are available, I periodically check whether the latest commit happened after my latest upload. If so, I re-clone the repository and upload again.</p>
  
  <p>If there is an entirely different, better approach of achieving this please let me know.</p>