Easy example of resolving Large file pushes using git-lfs

A while back I tried to push a commit back to my upstream repo in GitHub. I encountered an unpleasant message like the one below:

error: GH001: Large files detected. You may want to try Git Large File Storage – https://git-lfs.github.com

What does that mean?

Apparently, one of my files was over 100MB threshold allowed by the github free tier. I was stuck in the middle of the road on what do next. I could delete file or can take advantage of git-lfs

What is Git-lfs and what does to large files

Git-lfs is tool provided to help pushing commits with large files by uploading the large file to separate location called “git-lfs store” and replacing the file in the repo to a URL pointer in that location when push the commit upstream to the remote repo like GitHub. It also works with other public hosted git providers (BitBucket).

Getting Started

  1. First download git-lfs: https://git-lfs.github.com
  2. Setup gitlfs for your account typing the command:
    git lfs install
  3. Select the file types to track
    git lfs track --filename [path to file in repo
    git add .gitattributes
  4. Add the filename of the tracked file
    git add [filename]
  5. Finally commit and push to your remote policy
    git commit
    git push origin

Word of Caution

Examples in the git lfs documentation instructs users to track by all files by extions git lfs track [*.extension]. I have found this adde more complixity.

Only use git-lfs to target the file or files that are large. If left unchecked, git-lfs will take any file extension and push to git lfs-store.

You can always edit the tracking changes saved in .gitattributes file.

Fixing Git-lfs issues

It’s not say that git-lfs doesn’t its own set of challenges

In your repo, if you happen to get-lfs pointer instead of the file try running the command:
git lfs pull

Still unable to push commit to remote respository
Try using the migrate field (recommend in new branch)
git branch lfsfeature
git checkout lfsfeature
git lfs migrate import --include=[filename] -m "message"

Uninstalling Git-lfs

One time, I used in git-lfs a visual studio solution, which massive corrupted all the .csproj files in the soltuion our repo.

As a last resort if Git-Lfs has reeked unintended havoc on your repo like ours, you try uninstalling and ensuring tracking is limited to the files needed:

git lfs uninstall for versions over 1.10
git lfs uninitversions under 1.10

Additional References