code: private static void addRemote(Git git, String remoteName, String remoteUrl) throws GitAPIException,
                                                                                         URISyntaxException {
          String currentUrl = git.getRepository().getConfig().getString("remote", remoteName, "url");
          if (StringUtils.isNotEmpty(currentUrl)) {
              if (!currentUrl.equals(remoteUrl)) {
                  RemoteSetUrlCommand remoteSetUrl = git.remoteSetUrl();
                  remoteSetUrl.setName(remoteName);
                  remoteSetUrl.setUri(new URIish(remoteUrl));
                  remoteSetUrl.call();
              }
          } else {
              RemoteAddCommand remoteAdd = git.remoteAdd();
              remoteAdd.setName(remoteName);
              remoteAdd.setUri(new URIish(remoteUrl));
              remoteAdd.call();
          }
      }
docs: Adds a remote if it doesn't exist. If the remote exists but the URL is different, updates the URL
  
  @param git the Git repo
  @param remoteName the name oif the remote
  @param remoteUrl the URL of the remote
  
  @throws GitAPIException if a Git error occurs
  @throws URISyntaxException if the remote URL is an invalid Git URL