Getting all branches with JGit

How can I get all branches in a repository with JGit?
Let’s take an example repository. As we can see, it has 5 branches.
Here I found this example:

int c = 0;
List<Ref> call = new Git(repository).branchList().call();
for (Ref ref : call) {
    System.out.println("Branch: " + ref + " " + ref.getName() + " "
            + ref.getObjectId().getName());
    c++;
}
System.out.println("Number of branches: " + c);

But all I get is this:

  • Git not ignoring certain Xcode files in .gitignore
  • Git won't add modified file
  • Which file permissions are impacted by Git's core.sharedrepository setting?
  • hint: after resolving the conflicts, mark the corrected paths
  • How to publish to Github Pages from Travis CI?
  • Xcode 6 how to remove branch in origin
  • Branch: Ref[refs/heads/master=d766675da9e6bf72f09f320a92b48fa529ffefdc] refs/heads/master d766675da9e6bf72f09f320a92b48fa529ffefdc
    Number of branches: 1
    Branch: master
    

  • Add remote via JGit
  • Make a git branch equal to master again
  • How do I determine the correct git config setting to use in the global config file from an option name?
  • Where to find changes due to `git fetch`
  • git access permissions to repository files or paths
  • GIT_DISCOVERY_ACROSS_FILESYSTEM problem when working with terminal and MacFusion
  • One Solution collect form web for “Getting all branches with JGit”

    If it is the remote branches that you are missing, you have to set the ListMode of the ListBranchCommand to ALL or REMOTE. The default ListMode (null) returns only local branches.

    new Git( repository ).branchList().setListMode( ListMode.ALL ).call();
    
    Git Baby is a git and github fan, let's start git clone.