code: def get_local_repo_credentials(
      repo_data: RemoteRunRepoData,
      identity_file: Optional[PathLike] = None,
      oauth_token: Optional[str] = None,
      original_hostname: Optional[str] = None,
  ) -> RemoteRepoCreds:
      url = repo_data.make_url(RepoProtocol.HTTPS)  # no auth
      r = requests.get(f"{url}/info/refs?service=git-upload-pack")
      if r.status_code == 200:
          return RemoteRepoCreds(
              protocol=RepoProtocol.HTTPS,
              private_key=None,
              oauth_token=None,
          )
  
      if identity_file is not None:  # must fail if key is invalid
          identity_file = os.path.expanduser(identity_file)
          try:  # user provided ssh key
              return check_remote_repo_credentials(
                  repo_data,
                  RepoProtocol.SSH,
                  identity_file=identity_file,
              )
          except GitCommandError:
              url = repo_data.make_url(RepoProtocol.SSH)
              raise InvalidRepoCredentialsError(
                  f"Can't access `{url}` using the `{identity_file}` private SSH key"
              )
  
      if oauth_token is not None:
          try:  # user provided oauth token
              return check_remote_repo_credentials(
                  repo_data, RepoProtocol.HTTPS, oauth_token=oauth_token
              )
          except GitCommandError:
              url = repo_data.make_url(RepoProtocol.SSH, oauth_token)
              masked = len(oauth_token[:-4]) * "*" + oauth_token[-4:]
              raise InvalidRepoCredentialsError(
                  f"Can't access `{url}` using the `{masked}` token"
              )
  
      identities = get_host_config(
          original_hostname or repo_data.repo_host_name
      ).get("identityfile")
      if identities:  # must fail if key is invalid
          try:  # key from ssh config
              return check_remote_repo_credentials(
                  repo_data,
                  RepoProtocol.SSH,
                  identity_file=identities[0],
              )
          except GitCommandError:
              url = repo_data.make_url(RepoProtocol.SSH, oauth_token)
              raise InvalidRepoCredentialsError(
                  f"Can't access `{url}` using the `{identities[0]}` SSH private key"
              )
  
      if os.path.exists(gh_config_path):
          with open(gh_config_path, "r") as f:
              gh_hosts = yaml.load(f, Loader=yaml.FullLoader)
          oauth_token = gh_hosts.get(repo_data.repo_host_name, {}).get(
              "oauth_token"
          )
          if oauth_token is not None:
              try:  # token from gh config
                  return check_remote_repo_credentials(
                      repo_data,
                      RepoProtocol.HTTPS,
                      oauth_token=oauth_token,
                  )
              except GitCommandError:
                  pass
  
      if os.path.exists(default_ssh_key):
          try:  # default user key
              return check_remote_repo_credentials(
                  repo_data,
                  RepoProtocol.SSH,
                  identity_file=default_ssh_key,
              )
          except GitCommandError:
              pass
  
      raise InvalidRepoCredentialsError(
          "No valid default Git credentials found: ensure passing a valid `--token` or `--git-identity` to `dstack init`."
      )
  
file_path: dstack/src/dstack/_internal/core/services/repos.py
imports: import os
  from pathlib import Path
  from typing import Optional, Union
  import git
  import requests
  import yaml
  from git.exc import GitCommandError
  from dstack._internal.core.errors import DstackError
  from dstack._internal.core.models.config import RepoConfig
  from dstack._internal.core.models.repos import LocalRepo, RemoteRepo, RemoteRepoCreds, RemoteRunRepoData
  from dstack._internal.core.models.repos.base import Repo, RepoProtocol
  from dstack._internal.utils.path import PathLike
  from dstack._internal.utils.ssh import get_host_config, make_ssh_command_for_git, try_ssh_key_passphrase
label_desc: Use image node_id 1 for calling a global function with example usage: get_local_repo_credentials(repo_data, identity_file, oauth_token, original_hostname) and returns: RemoteRepoCreds, check_remote_repo_credentials, check_remote_repo_credentials, check_remote_repo_credentials, check_remote_repo_credentials, check_remote_repo_credentials