11
Jun

Java code to checkout git code

jars dependency:
==================

jsch-0.1.42.jar
org-eclipse-jgit.jar
slf4j-api-1.7.26.jar
slf4j-simple-1.7.26.jar

Code snippet:
==============

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;

public class abc {

private static String REMOTE_URL = “https://github.com/feature/repository.git”;

public static void main(String[] args) throws GitAPIException, IOException, InterruptedException {
gitClone();
}

public static void gitClone() throws GitAPIException, IOException, InterruptedException {
final File localPath = new File(“./TestRepo”);

System.out.println(“Cloning from ” + REMOTE_URL + ” to ” + localPath);

Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath)
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(“x”, “xxxx”)).call();

Thread.sleep(5000);
}

}