File gitDir = new File(localRepo, ".git");
if (!gitDir.exists()) {
LOG.info("Cloning remote repo " + repo);
CloneCommand command = Git.cloneRepository().setCredentialsProvider(credentials).
setURI(repo).setDirectory(localRepo).setRemote(remoteName);
git = command.call();
} else {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(gitDir)
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree