Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Setting-up Git Large File Storage on a GitHub repository

Help! I just committed some large files to GitHub and now I can’t push them because they’re too big.

The good news is that it’s quite easy to recover from this messy situation and set-up Git Large File Storage to handle the big files.

The situation

I ran several commits and then realised that they had been unsuccessful. The error message I received was as follows:

remote: error: File /weights/last.pt is 128.70 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/AdamDimech/myrepo.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/AdamDimech/myrepo.git'

The solution

Part 1: Install Git LFS

Because I was working on Windows Subsystem for Linux (WSL2), I needed to install Git LFS via the following command:

sudo apt-get install git-lfs

Otherwise on Windows, the following command in Git-BASH will work:

git lfs install

Part 2: Reverse the commits without deleting my files

First, I needed to check how many commits ahead I was:

git log origin/main..main

(If you are still using master as your main branch, then change the code accordingly)

This indicated that I was three commits head of the main branch, so I entered the following command to rescind them:

git reset --soft HEAD~3

Part 3: Set-up Git LFS on the repo

The next step was to tell GitHub which types of files needed to be pushed to Git LFS:

git lfs track "*.pt"

Next, I needed to ensure that .gitattributes was tracked:

git add .gitattributes

Then it was a case of pushing the updates back to the repo:

git add .
git commit -am "Upload files to repository, large files to LFS"
git push

It should be noted that every GitHub account using Git Large File Storage receives 1 GiB of free storage and 1 GiB a month of free bandwidth. If the bandwidth and storage quotas are not enough, you can choose to purchase an additional quota for Git LFS. Details are available on the GitHub website.

   

Comments

No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.