public static void createBranch(Table table, AlterTableSnapshotRefSpec.CreateSnapshotRefSpec createBranchSpec) {
    String branchName = createBranchSpec.getRefName();
    boolean refExistsAsBranch = refExistsAsBranch(table, branchName);
    if (createBranchSpec.isIfNotExists() && refExistsAsBranch) {
      return;
    }
    boolean isReplace = createBranchSpec.isReplace() && refExistsAsBranch;
    Long snapshotId = null;
    if (createBranchSpec.getSnapshotId() != null) {
      snapshotId = createBranchSpec.getSnapshotId();
    } else if (createBranchSpec.getAsOfTime() != null) {
      snapshotId = SnapshotUtil.snapshotIdAsOfTime(table, createBranchSpec.getAsOfTime());
    } else if (createBranchSpec.getAsOfTag() != null) {
      String tagName = createBranchSpec.getAsOfTag();
      SnapshotRef snapshotRef = table.refs().get(tagName);
      if (snapshotRef != null && snapshotRef.isTag()) {
        snapshotId = snapshotRef.snapshotId();
      } else {
        throw new IllegalArgumentException(String.format("Tag %s does not exist", tagName));
      }
    } else {
      snapshotId = Optional.ofNullable(table.currentSnapshot()).map(Snapshot::snapshotId).orElse(null);
    }
    ManageSnapshots manageSnapshots = table.manageSnapshots();
    if (snapshotId != null) {
      createOrReplaceBranch(manageSnapshots, table, isReplace, branchName, snapshotId);
    } else if (isReplace) {
      throw new IllegalArgumentException(
          "Cannot complete replace branch operation on " + branchName + ", main has no snapshot");
    } else {
      LOG.info("Creating a branch {} on an empty iceberg table {}", branchName, table.name());
      manageSnapshots.createBranch(branchName);
    }

    setCreateBranchOptionalParams(createBranchSpec, manageSnapshots, branchName);
    manageSnapshots.commit();
  }
Create a branch on the iceberg table
@param table the iceberg table
@param createBranchSpec Get the basic parameters needed to create a branch
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergSnapshotRefExec.java