navy1978
navy1978

Reputation: 1439

Get all branches before cloning a repo

I'm writing an utility in swing that show all my projects and should let me clone a specific repo and also select the branch I want to switch to, once the cloning process is finished.

The only problem is that in order to show the branches as far as I can see you need to clone the repo first.

Is there a workaround for that?

Upvotes: 1

Views: 62

Answers (1)

centic
centic

Reputation: 15872

You can list tags/heads on remote repositories via the following snippet:

    Collection<Ref> refs = Git.lsRemoteRepository()
            .setHeads(true)
            .setTags(true)
            .setRemote(REMOTE_URL)
            .call();

See also this ready-to-run snippet in the jgit-cookbook

Upvotes: 1

Related Questions