How to determine the latest committed branch in the Git repository? I want to clone only the recently updated branch instead of cloning all the branches despite of whether it is merged to master (default branch) or not.
LsRemoteCommand remoteCommand = Git.lsRemoteRepository();
Collection <Ref> refs = remoteCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password))
.setHeads(true)
.setRemote(uri)
.call();
for (Ref ref : refs) {
System.out.println("Ref: " + ref.getName());
}
//cloning the repo
CloneCommand cloneCommand = Git.cloneRepository();
result = cloneCommand.setURI(uri.trim())
.setDirectory(localPath).setBranchesToClone(branchList)
.setBranch("refs/heads/branchName")
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName,password)).call();
Can anyone help me on this?