code: protected void createBranchIfNeeded(String branch) throws Exception {
          fetch(); // in case the branch is not known locally
          if (localRepo.findRef(branch) == null) {
              git.branchCreate()
                 .setName(branch)
                 .setUpstreamMode(SetupUpstreamMode.TRACK)
                 .setStartPoint("origin/" + branch)
                 .call();
          }
      }
docs: Create a local branch for remote tracking if it doesn't exist already.