Git LFS fail for Spaces with Github Workflow
I am trying to setup Github Workflow for a Hugging Face space.But I receive following error message:remote: -------------------------------------------------------------------------        
remote: Your push was rejected because it contains binary files.        
remote: Please use https://git-lfs.github.com/ to store binary files.        
remote: See also: https://hf.co/docs/hub/adding-a-model#uploading-your-files        
remote: -------------------------------------------------------------------------        
remote: Offending files:        
remote:  - ballon.jpg (ref: refs/heads/main)        
remote:  - fountain.jpg (ref: refs/heads/main)        
remote:  - wolf.jpg (ref: refs/heads/main)        
To https://huggingface.co/spaces/satpalsr/RegNet-Image-Classification
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://huggingface.co/spaces/satpalsr/RegNet-Image-Classification'
Error: Process completed with exit code 1.Modified Code I tried:name: Sync to Hugging Face hub
on:
  push:
    branches: [main]

  # to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  sync-to-hub:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
          lfs: true
      - name: Checkout LFS objects
        run: git lfs checkout
      - name: Push to hub
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
        run: git push --force https://satpalsr:$HF_TOKEN@huggingface.co/spaces/satpalsr/RegNet-Image-Classification main
2022-04-09T19:12:30Z
Hey there! As per the error message, the binary files should be tracked withgit lfs.What you can do is# Track the files being rejected
git lfs track "your_file" # or *.your_extension

# Track things 
git lfs installNote that if you have commits with those files, it will still be rejected since the binary files are in previous commits without git lfs, so you will need to change that.
2022-04-10T05:13:11Z
Not working!Added these lines & even created a new test space.Though the .jpg files are tracked successfully, the exact same error message repeats.To reproduce:Create a test space at Hugging Face.Create a repository on Github.Add a secret HF token in the Github repo.Add some image files to the Github repo.Set up the GitHub action workflow.
2022-04-11T10:28:35Z
if the git repo is public, can you zip the whole repo (including .git) and share it somewhere? Thanks!
2022-04-13T14:14:31Z
Hey@julien-c, here is what you need:Github Repo:https://github.com/satpalsr/HF-workflowGithub repo zip (including .git) : Check DMSpace Link:https://huggingface.co/spaces/satpalsr/workflow-test
2022-10-19T22:30:15Z
I face the same issue as well, I had previous commits to binary files without lfs commits but later on, I enabled git lfs but still my workflow fails since the file is there in the previous commits. How do I fix this?
2022-10-19T23:12:51Z
Nevermind, found an answer to remove git history of all large file by running the following git commandgit filter-branch --index-filter --f "git rm -rf --cached --ignore-unmatch “PATH TO FILE” HEADgit push origin --force --all
2022-10-21T21:01:48Z
arghh, i am running into the same issue…Is there any way to avoid rewriting the commit history (which is what git filter-branch will do iiuc).(Btw, i think there is a"missing on your command at the end@Clatonh)
2023-12-15T14:42:32Z
same issue here! track the files but keep the same error
2023-12-15T19:03:13Z
hi@joselobenitezg,You probably have the offending files committed to the git history without LFS, it’s a common issue. Please reset your commit history, removing the commits with files without LFS tracking.
2023-12-15T20:15:02Z
You are right! Solved now!
2024-01-05T03:39:26Z
Hi I am getting similar error. I added this lines of code in yaml file still not working.- name: LFS Install
        run: git lfs install
      - name: LFS Track
        run: git lfs track *.mp4
      - name: Checkout LFS objects
        run: git lfs checkoutstill showing following error.Screenshot 2024-01-04 at 7.39.09 PM1588×552 80.9 KB
2024-01-05T05:01:41Z
hi@KushwanthK,The message states that your repo has a .mp4 file commit to the git history, please make sure you remove it from the historyGit LFS fail for Spaces with Github WorkflowSpacesNevermind, found an answer to remove git history of all large file by running the following git command 

git filter-branch --index-filter --f "git rm -rf --cached --ignore-unmatch “PATH TO FILE” HEAD 
git push origin --force --allthen track it withgit lfs track "*.mp4"
2024-01-05T07:40:29Z
yes thanksjust added this in yaml and it works.- name: reset commit
        run: git filter-branch --force --index-filter "git rm --cached --ignore-unmatch output_sample.mp4" --prune-empty --tag-name-filter cat -- --allreference followed this.EducativeEducative Answers - Trusted Answers to Developer QuestionsLevel up your coding skills. No more passive learning. Interactive in-browser environments keep you engaged and test your progress as you go.
2024-03-19T18:43:03Z
After I undid my last commit and followed your instructions, I was able to add the new staged changes to the staging area, committing, and then pushing without a problem. Thank you.
2024-04-03T21:11:40Z
Just had the same issue with a .sqlite3 file.Decided to make a new space, then clone it, edit .gitattributes (already provided by HF) to add the file-format there.*.sqlite3 filter=lfs diff=lfs merge=lfs -textRunninggit lfs track "*.sqlite3"confirmed that it was already tracked with lfs there.Then push.Then add all my stuff for the project from a different folder - push - works.
2024-05-17T21:28:58Z
Below is content of my yml file on Github Workflow :name: Sync to Hugging Face hub
on:
  push:
    branches: [main]

  # to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  sync-to-hub:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          lfs: false

      - name: Ignore large files
        run : git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch "research/codebase/3_vectorstore/db_faiss/index.faiss"' HEAD

    
      - name: Push to hub
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
        run: git push --force https://rahul-bhoyar-1995:$HF_TOKEN@huggingface.co/spaces/KaggleGPT/KaggleGPT mainBut I am still getting this error.