title: Fetching all Git branches programmatically with JGit
body: <p>I am using <a href="https://www.eclipse.org/jgit/" rel="nofollow noreferrer">JGit</a> in a project and I would like to achieve the programmatic equivalent of a <code>git --fetch all</code>. The <a href="http://download.eclipse.org/jgit/site/4.11.0.201803080745-r/apidocs/index.html" rel="nofollow noreferrer">JGit API Documentation</a> provides three <a href="http://download.eclipse.org/jgit/site/4.11.0.201803080745-r/apidocs/org/eclipse/jgit/api/FetchCommand.html#setRefSpecs-java.lang.String...-" rel="nofollow noreferrer">alternative fetch operations</a> called <code>setRefSpecs(...)</code>. All alternatives require the developer to define the concrete <code>RefSpecs</code> to update.</p>
  
  <p>I expect that I have to query the repository for all available <code>RefSpecs</code> and aggregate them for one combined fetch call (similar to <a href="https://stackoverflow.com/questions/24518782/getting-all-branches-with-jgit">Getting all branches with JGit
  </a>). However, I do not understand how to transform a <code>Ref</code> into a <code>RefSpec</code>. I would appreciate any pointer here.</p>
  
  <p>Very related to this, I am also not sure how to prune local branches that have been deleted remotely (<code>fetch --prune</code>). Am I right to assume that setting <code>setRemoveDeletedRefs</code> to <code>true</code> achieves exactly this?</p>