HfHub.Git (HfHub v0.2.0)

Copy Markdown View Source

Git operations for HuggingFace Hub repositories.

Provides branch, tag, and commit management.

Examples

# Create a branch
{:ok, info} = HfHub.Git.create_branch("my-org/my-model", "feature-branch")

# Create a tag with a message
{:ok, info} = HfHub.Git.create_tag("my-model", "v1.0", message: "Release v1.0")

# List all refs
{:ok, refs} = HfHub.Git.list_refs("bert-base-uncased")

# List commits
{:ok, commits} = HfHub.Git.list_commits("bert-base-uncased")

# Super squash (destructive)
:ok = HfHub.Git.super_squash("my-model", message: "Squashed history")

Summary

Functions

Creates a new branch in a repository.

Creates a new tag in a repository.

Deletes a branch from a repository.

Deletes a tag from a repository.

Lists commits in a repository.

Lists all refs (branches, tags) in a repository.

Squashes all commits into a single commit.

Types

repo_type()

@type repo_type() :: :model | :dataset | :space

Functions

create_branch(repo_id, branch, opts \\ [])

@spec create_branch(String.t(), String.t(), keyword()) ::
  {:ok, HfHub.Git.BranchInfo.t()} | {:error, term()}

Creates a new branch in a repository.

Options

  • :token - Authentication token
  • :repo_type - Repository type (:model, :dataset, :space). Defaults to :model.
  • :revision - Source revision to branch from. Defaults to "main".
  • :exist_ok - Don't error if branch exists. Defaults to false.

Examples

{:ok, info} = HfHub.Git.create_branch("my-model", "feature-branch")
{:ok, info} = HfHub.Git.create_branch("my-model", "hotfix", revision: "v1.0")
{:ok, info} = HfHub.Git.create_branch("my-model", "dev", exist_ok: true)

create_tag(repo_id, tag, opts \\ [])

@spec create_tag(String.t(), String.t(), keyword()) ::
  {:ok, HfHub.Git.TagInfo.t()} | {:error, term()}

Creates a new tag in a repository.

Options

  • :token - Authentication token
  • :repo_type - Repository type. Defaults to :model.
  • :revision - Revision to tag. Defaults to "main".
  • :message - Optional tag message (creates annotated tag).
  • :exist_ok - Don't error if tag exists. Defaults to false.

Examples

{:ok, info} = HfHub.Git.create_tag("my-model", "v1.0")
{:ok, info} = HfHub.Git.create_tag("my-model", "v2.0",
  revision: "abc123", message: "Release v2.0")

delete_branch(repo_id, branch, opts \\ [])

@spec delete_branch(String.t(), String.t(), keyword()) :: :ok | {:error, term()}

Deletes a branch from a repository.

Options

  • :token - Authentication token
  • :repo_type - Repository type. Defaults to :model.

Examples

:ok = HfHub.Git.delete_branch("my-model", "old-branch")

delete_tag(repo_id, tag, opts \\ [])

@spec delete_tag(String.t(), String.t(), keyword()) :: :ok | {:error, term()}

Deletes a tag from a repository.

Options

  • :token - Authentication token
  • :repo_type - Repository type. Defaults to :model.

Examples

:ok = HfHub.Git.delete_tag("my-model", "old-tag")

list_commits(repo_id, opts \\ [])

@spec list_commits(
  String.t(),
  keyword()
) :: {:ok, [HfHub.Git.CommitInfo.t()]} | {:error, term()}

Lists commits in a repository.

Options

  • :token - Authentication token
  • :repo_type - Repository type. Defaults to :model.
  • :revision - Branch/tag/commit to list from. Defaults to "main".

Examples

{:ok, commits} = HfHub.Git.list_commits("bert-base-uncased")
Enum.take(commits, 10)  # First 10 commits

list_refs(repo_id, opts \\ [])

@spec list_refs(
  String.t(),
  keyword()
) :: {:ok, HfHub.Git.GitRefs.t()} | {:error, term()}

Lists all refs (branches, tags) in a repository.

Options

  • :token - Authentication token
  • :repo_type - Repository type. Defaults to :model.
  • :include_pull_requests - Include PR refs. Defaults to false.

Examples

{:ok, refs} = HfHub.Git.list_refs("bert-base-uncased")
refs.branches  # [%BranchInfo{name: "main", ...}]
refs.tags      # [%TagInfo{name: "v1.0", ...}]

super_squash(repo_id, opts \\ [])

@spec super_squash(
  String.t(),
  keyword()
) :: :ok | {:error, term()}

Squashes all commits into a single commit.

WARNING: This is a destructive operation. Use with caution.

Options

  • :token - Authentication token (required)
  • :repo_type - Repository type. Defaults to :model.
  • :branch - Branch to squash. Defaults to "main".
  • :message - Commit message for squashed commit.

Examples

:ok = HfHub.Git.super_squash("my-model", message: "Squashed history")