Skip to content

Instantly share code, notes, and snippets.

@Hansimov
Last active July 15, 2024 19:59
Show Gist options
  • Save Hansimov/6002fddd5f7a49c210ed1b3757acb271 to your computer and use it in GitHub Desktop.
Save Hansimov/6002fddd5f7a49c210ed1b3757acb271 to your computer and use it in GitHub Desktop.
Sync Github repo to Huggingface space

Push Github Repo to Huggingface Space

Create a huggingface token

Put it in the repo secrets with name like HF_TOKEN in related Github repo setitngs:

Run following commands in the git root folder:

git remote add space https://huggingface.co/spaces/<user_name>/<repo_name>
# git remote -v
git remote set-url space https://<user_name>:<token>@huggingface.co/spaces/<user_name>/<repo_name>
git push --force space main
  • <repo_path> is in the form of:
    • models: <user_name>/<repo_name>
    • datasets: datasets/<user_name>/<repo_name>
    • spaces: spaces/<user_name>/<repo_name>

Sync to Huggingface Space with Github Actions

Then add a sync_to_huggingface_space.yml in .github/workflows:

  • Replace the <user_name> (x2) and <repo_name> in the last line for current repo.
  • The HF_TOKEN name should be the same with the one specified in the step above.
name: Sync to Hugging Face hub
on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  sync-to-hub:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          lfs: true
      - name: Push to hub
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
        run: git push -f https://<user_name>:[email protected]/spaces/<user_name>/<repo_name> main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment