code: public Git cloneRepository(String remoteUrl, Path localPath, String username, String password) {
          try {
              return Git.cloneRepository()
                  .setURI(remoteUrl)
                  .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password))
                  .setDirectory(localPath.toFile())
                  .call();
          } catch (GitAPIException e) {
              throw new IllegalStateException(e);
          }
      }
docs: Clones a private remote git repository. Caller is responsible of closing git repository.
  
  @param remoteUrl
  to connect.
  @param localPath
  where to clone the repo.
  @param username
  to connect
  @param password
  to connect
  
  @return Git instance. Caller is responsible to close the connection.