code: public GitRepository build() {
          try {
              val providers = this.credentialsProviders.toArray(CredentialsProvider[]::new);
              if (this.repositoryDirectory.exists()) {
                  val git = Git.open(this.repositoryDirectory);
                  git.checkout()
                      .setName(this.activeBranch)
                      .call();
                  return new GitRepository(git, this.credentialsProviders);
              }
  
              val cloneCommand = Git.cloneRepository()
                  .setProgressMonitor(new LoggingGitProgressMonitor())
                  .setURI(this.repositoryUri)
                  .setDirectory(this.repositoryDirectory)
                  .setBranch(this.activeBranch)
                  .setCredentialsProvider(new ChainingCredentialsProvider(providers));
  
              if (StringUtils.hasText(this.branchesToClone) || "*".equals(branchesToClone)) {
                  cloneCommand.setCloneAllBranches(true);
              } else {
                  cloneCommand.setBranchesToClone(StringUtils.commaDelimitedListToSet(this.branchesToClone)
                      .stream()
                      .map(GitRepositoryBuilder::getBranchPath)
                      .collect(Collectors.toList()));
              }
              return new GitRepository(cloneCommand.call(), credentialsProviders);
          } catch (final Exception e) {
              throw new IllegalArgumentException(e.getMessage(), e);
          }
      }
docs: Build git repository.
  
  @return the git repository