Tracking Large Files in GitHub: Git LFS

Last week while working on a project, I ran into a nasty error message while trying to push a commit before taking a break. My commit was rejected due to me adding a large video file (129 MB), the error message expressed that the limit was 100MB. I tried deleting the video from my project and committing again but I got the same error as the file is still stored in memory. After searching google and trying a handful of different approaches I was stuck. I finally came across a solution the next day. I hope this post will find any future programmers and save them the headache I endured trying to fix this. We will be using Git LFS(Large File Storage) to track our large files.

Fixing the Error

If you have already made the mistake of trying to commit before using Git LFS and encountered the same error. Run

git log 

and find the last commit in history BEFORE adding your video into your project.

git reset --hard ${commit id}

Then move forward with installation.

Installation - Git LFS

What you need to first is to make sure you have Git LFS installed.

brew install git-lfs

Git LFS replaces your large files with text pointers in git and stores your files on a remote server. You can learn more .

Now run

git lfs install

in your command line to make sure you see the updated version of lfs installed. If it hasn’t already, it will now install. If you want to make sure it was successful run “ git lfs install” once more and you should see.

Updated git hooks.
Git LFS initialized.

This is when you know you are ready to start tracking your files!

Tracking your Files Before Committing

  1. Navigate into the working parent directory of your project where you have your large files.
  2. Run
git lfs track "* ${your-file-type}"

Example if it was an .mp4 file

git lfs track "*.mp4"

With the * you are saying I want Git LFS to track all your .mp4 files.

3. Make sure .gitattributes file is tracked:

git add .gitattributes

4. Commit your file

git add ${your-file-path}  ex...(public/videos/video.mp4)
OPTIONAL: run "git lfs status"
to double check if the file was added before committing.
git commit -m "Add design file"
git push

That’s it, your commit should be successful!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store