Hub documentation
GitHub Actions
单点登录(SSO) 审计日志 存储区域 用于私有数据集的 Data Studio 资源组(访问控制) 高级计算选项 高级安全 令牌管理 服务账号 发布者分析 门控组集合 网络安全 下载分析 速率限制 博客文章
PRO 计划 仓库 入门仓库 仓库设置 存储限制 存储后端(Xet) 本地缓存 Pull Requests 与 Discussions 通知 集合 Webhooks GitHub Actions Notebooks 后续步骤 许可证
模型 数据集 Spaces Spaces 概览 Spaces GPU 升级 Spaces ZeroGPU Spaces 开发模式 Spaces 磁盘使用量与存储 Spaces 自定义域名 Spaces 作为 MCP 服务器 Spaces 作为智能体工具 将 Spaces 用作 API 端点 Gradio Spaces Streamlit Spaces 静态 HTML Spaces Docker Spaces 嵌入您的 Space 使用 Docker 运行 Spaces Spaces 配置参考 使用 HF 登录按钮 精选 Spaces Spaces 更新日志 高级主题
存储桶 new 容器镜像 new 任务 智能体 智能体概述 Hugging Face AI 智能体 CLI Hugging Face MCP 服务器 Hugging Face Agent Skills 使用 HF SDK 构建智能体 使用 llama.cpp 的本地代理 Agent 库 会话跟踪格式
其他 GitHub Actions
您可以使用 GitHub Actions 将您的 GitHub 仓库自动同步到 Hugging Face Hub。官方的 huggingface/hub-sync action 支持同步 Models、Datasets 和 Spaces。
对于无密钥发布——无需存储或轮换
HF_TOKEN密钥——请参阅 Trusted Publishers,它会在每次运行开始时,将 GitHub Actions 内置的 OIDC 令牌交换为短时效、仓库范围的 Hub 令牌。
设置
- 创建一个具有目标仓库write权限的 Hugging Face 访问令牌。为了获得更好的安全性,请使用仅限定于您正在同步到的仓库的细粒度令牌。
- 在您的仓库设置中,将该令牌添加为名为
HF_TOKEN的 GitHub 机密。 - 在您的仓库中添加一个工作流文件(例如
.github/workflows/sync-to-hub.yml)。
基本用法
name: Sync to Hugging Face Hub
on:
push:
branches: [main]
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: huggingface/[email protected]
with:
github_repo_id: ${{ github.repository }}
huggingface_repo_id: username/repo-name
hf_token: ${{ secrets.HF_TOKEN }}默认情况下,这会同步到 Space。若要同步模型或数据集,请设置 repo_type 参数:
- uses: huggingface/[email protected]
with:
github_repo_id: ${{ github.repository }}
huggingface_repo_id: username/my-dataset
hf_token: ${{ secrets.HF_TOKEN }}
repo_type: dataset参数
| 参数 | 必需 | 默认 | 描述 |
|---|---|---|---|
github_repo_id | 是的 | — | GitHub 仓库(使用 ${{ github.repository }}) |
huggingface_repo_id | 是的 | — | Hub 上的目标仓库 (username/repo-name) |
hf_token | 是的 | — | Hugging Face 访问令牌 |
repo_type | No | space | space、model 或 dataset |
space_sdk | No | gradio | gradio、streamlit、docker 或 static |
private | No | false | 是否将仓库创建为私有 |
subdirectory | No | . | 同步特定子目录(适用于 monorepo) |
该操作使用 hf CLI 将您的文件镜像到 Hub——它并非 git 到 git 的同步。它会自动排除 .github/ 和 .git/ 目录,并镜像删除操作(从 GitHub 中删除的文件也会从 Hub 中删除)。
对于更复杂的工作流(例如构建步骤、自定义上传逻辑),您可以直接在您的工作流中安装并使用 hf CLI。
有关 Spaces 的特定指南(文件大小限制、LFS 处理),请参阅 使用 GitHub Actions 管理 Spaces。
Update on GitHub