def init_git_repo(args, at_init: bool = False):
    """
    Args:
    Initializes a git repo in `args.hub_model_id`.
        at_init (`bool`, *optional*, defaults to `False`):
            Whether this function is called before any training or not. If `self.args.overwrite_output_dir` is `True`
            and `at_init` is `True`, the path to the repo (which is `self.args.output_dir`) might be wiped out.
    """
    deprecation_message = (
        "Please use `huggingface_hub.Repository`. "
        "See `examples/unconditional_image_generation/train_unconditional.py` for an example."
    )
    deprecate("init_git_repo()", "0.10.0", deprecation_message)

    if hasattr(args, "local_rank") and args.local_rank not in [-1, 0]:
        return
    hub_token = args.hub_token if hasattr(args, "hub_token") else None
    use_auth_token = True if hub_token is None else hub_token
    if not hasattr(args, "hub_model_id") or args.hub_model_id is None:
        repo_name = Path(args.output_dir).absolute().name
    else:
        repo_name = args.hub_model_id
    if "/" not in repo_name:
        repo_name = get_full_repo_name(repo_name, token=hub_token)

    try:
        repo = Repository(
            args.output_dir,
            clone_from=repo_name,
            use_auth_token=use_auth_token,
            private=args.hub_private_repo,
        )
    except EnvironmentError:
        if args.overwrite_output_dir and at_init:
            # Try again after wiping output_dir
            shutil.rmtree(args.output_dir)
            repo = Repository(
                args.output_dir,
                clone_from=repo_name,
                use_auth_token=use_auth_token,
            )
        else:
            raise

    repo.git_pull()

    # By default, ignore the checkpoint folders
    if not os.path.exists(os.path.join(args.output_dir, ".gitignore")):
        with open(os.path.join(args.output_dir, ".gitignore"), "w", encoding="utf-8") as writer:
            writer.writelines(["checkpoint-*/"])

    return repo

    Args:
    Initializes a git repo in `args.hub_model_id`.
        at_init (`bool`, *optional*, defaults to `False`):
            Whether this function is called before any training or not. If `self.args.overwrite_output_dir` is `True`
            and `at_init` is `True`, the path to the repo (which is `self.args.output_dir`) might be wiped out.
    
promptist/diffusers/src/diffusers/hub_utils.py