# Git LFS fail for Spaces with Github Workflow

**URL:** <https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642>\
**Category:** Spaces\
**Created:** [April 9, 2022, 12:13pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642 "2022-04-09T12:13:30Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![satpalsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/satpalsr/32/3553_2.png) [@satpalsr](https://discuss.huggingface.co/u/satpalsr)\
**Post date:** [April 9, 2022, 12:13pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/1 "2022-04-09T12:13:31Z")

</div>

I am trying to setup Github Workflow for a Hugging Face space.  
But I receive following error message:

```auto
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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![osanseviero](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/osanseviero/32/38738_2.png) [@osanseviero](https://discuss.huggingface.co/u/osanseviero)\
**Post date:** [April 9, 2022, 7:12pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/2 "2022-04-09T19:12:30Z")

</div>

Hey there! As per the error message, the binary files should be tracked with `git lfs`.

What you can do is

```auto
# Track the files being rejected
git lfs track "your_file" # or *.your_extension

# Track things 
git lfs install

```

Note 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.

---

<div class="post-metadata">

**Author:** ![satpalsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/satpalsr/32/3553_2.png) [@satpalsr](https://discuss.huggingface.co/u/satpalsr)\
**Post date:** [April 10, 2022, 5:13am UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/3 "2022-04-10T05:13:11Z")

</div>

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:

1. Create a test space at Hugging Face.
2. Create a repository on Github.
3. Add a secret HF token in the Github repo.
4. Add some image files to the Github repo.
5. Set up the GitHub action workflow.

---

<div class="post-metadata">

**Author:** ![julien-c](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/julien-c/32/41937_2.png) [@julien-c](https://discuss.huggingface.co/u/julien-c)\
**Post date:** [April 11, 2022, 10:28am UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/4 "2022-04-11T10:28:35Z")

</div>

if the git repo is public, can you zip the whole repo (including .git) and share it somewhere? Thanks!

---

<div class="post-metadata">

**Author:** ![satpalsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/satpalsr/32/3553_2.png) [@satpalsr](https://discuss.huggingface.co/u/satpalsr)\
**Post date:** [April 13, 2022, 2:14pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/5 "2022-04-13T14:14:31Z")

</div>

Hey @julien-c , here is what you need:  
Github Repo: [https://github.com/satpalsr/HF-workflow](https://github.com/satpalsr/HF-workflow)  
Github repo zip (including .git) : Check DM  
Space Link: [https://huggingface.co/spaces/satpalsr/workflow-test](https://huggingface.co/spaces/satpalsr/workflow-test)

---

<div class="post-metadata">

**Author:** ![Clatonh](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Clatonh](https://discuss.huggingface.co/u/Clatonh)\
**Post date:** [October 19, 2022, 10:30pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/6 "2022-10-19T22:30:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Clatonh](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Clatonh](https://discuss.huggingface.co/u/Clatonh)\
**Post date:** [October 19, 2022, 11:12pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/7 "2022-10-19T23:12:51Z")

</div>

Nevermind, 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 --all

---

<div class="post-metadata">

**Author:** ![VictorSanh](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/victorsanh/32/21405_2.png) [@VictorSanh](https://discuss.huggingface.co/u/VictorSanh)\
**Post date:** [October 21, 2022, 9:01pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/8 "2022-10-21T21:01:48Z")

</div>

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 )

---

<div class="post-metadata">

**Author:** ![joselobenitezg](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/joselobenitezg/32/22024_2.png) [@joselobenitezg](https://discuss.huggingface.co/u/joselobenitezg)\
**Post date:** [December 15, 2023, 2:42pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/9 "2023-12-15T14:42:32Z")

</div>

same issue here! track the files but keep the same error

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [December 15, 2023, 7:03pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/10 "2023-12-15T19:03:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joselobenitezg](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/joselobenitezg/32/22024_2.png) [@joselobenitezg](https://discuss.huggingface.co/u/joselobenitezg)\
**Post date:** [December 15, 2023, 8:15pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/11 "2023-12-15T20:15:02Z")

</div>

You are right! Solved now!

---

<div class="post-metadata">

**Author:** ![KushwanthK](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KushwanthK](https://discuss.huggingface.co/u/KushwanthK)\
**Post date:** [January 5, 2024, 3:39am UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/12 "2024-01-05T03:39:26Z")

</div>

Hi I am getting similar error. I added this lines of code in yaml file still not working.

```auto
      - name: LFS Install
        run: git lfs install
      - name: LFS Track
        run: git lfs track *.mp4
      - name: Checkout LFS objects
        run: git lfs checkout

```

still showing following error.

 ![Screenshot 2024-01-04 at 7.39.09 PM](https://us1.discourse-cdn.com/hellohellohello/original/3X/0/1/017246366b3631708ac75d889be713124a6301b8.png)

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [January 5, 2024, 5:01am UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/13 "2024-01-05T05:01:41Z")

</div>

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 history

> [@Git LFS fail for Spaces with Github Workflow](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/7):
>
> Nevermind, 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 --all

then track it with `git lfs track "*.mp4"`

---

<div class="post-metadata">

**Author:** ![KushwanthK](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KushwanthK](https://discuss.huggingface.co/u/KushwanthK)\
**Post date:** [January 5, 2024, 7:40am UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/14 "2024-01-05T07:40:29Z")

</div>

yes thanks  
just added this in yaml and it works.

```auto
 - name: reset commit
        run: git filter-branch --force --index-filter "git rm --cached --ignore-unmatch output_sample.mp4" --prune-empty --tag-name-filter cat -- --all

```

reference followed this.

> **[Educative Answers - Trusted Answers to Developer Questions](https://www.educative.io/answers/how-to-remove-sensitive-files-and-their-commits-from-git-history)**
>
> Level up your coding skills. No more passive learning. Interactive in-browser environments keep you engaged and test your progress as you go.

---

<div class="post-metadata">

**Author:** ![vincemonte](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vincemonte](https://discuss.huggingface.co/u/vincemonte)\
**Post date:** [March 19, 2024, 6:43pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/15 "2024-03-19T18:43:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RJuro](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rjuro/32/25454_2.png) [@RJuro](https://discuss.huggingface.co/u/RJuro)\
**Post date:** [April 3, 2024, 9:11pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/16 "2024-04-03T21:11:40Z")

</div>

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 -text`

Running `git 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.

---

<div class="post-metadata">

**Author:** ![rahul-bhoyar-1995](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rahul-bhoyar-1995/32/27096_2.png) [@rahul-bhoyar-1995](https://discuss.huggingface.co/u/rahul-bhoyar-1995)\
**Post date:** [May 17, 2024, 9:28pm UTC](https://discuss.huggingface.co/t/git-lfs-fail-for-spaces-with-github-workflow/16642/17 "2024-05-17T21:28:58Z")

</div>

Below is content of my yml file on Github Workflow :

```auto
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 main

```

But I am still getting this error.

![Screenshot 2024-05-17 at 11.28.06 PM](https://us1.discourse-cdn.com/hellohellohello/original/3X/8/8/88328e06d0061cab9f709d5565197d129ec6977b.png)
