Git LFS: A One Way Street

When I first used Git Large File Storage, I thought it was amazing. I also think those who created it deserve a many thank yous and praise. The idea of using pointer files to locally cache large files is a concept I’m still wrapping my head around understanding but they made it easy enough to use for everyone. It really only takes two commands – install Git LFS from the project website and “git lfs install” once inside your repository’s root folder.

The documentation is a bit spread out all over the place, so let me save you some time by suggesting you skip tracking with commands and using your .gitattributes to ensure you capture all of the file types that tend to run over 100 MB. Start from the beginning as you can run into quite a few issues. Otherwise, you might end up with the view below.

But don’t worry, I’m here to stop you from making this worse. Whatever you do do not remove the large files and proceed to make another commit!! The best plan of action is to amend the commit by removing the file from git cache completely to stop git from tracking it and add it to git lfs for tracking. If you’ve happened to make multiple commits, do the following:

  1. Find the last good commit free of the file causing trouble using git log and retain the commit hash
  2. Rebase using git rebase -i <commit hash> to edit the commit/s with the large file by removing the file using git rm –cached <file>
  3. From here git commit –amend -C HEAD

Now, let’s say you happened to make multiple commits and can’t exactly track down the point at which said file was first introduced. What is one to do? I wish I had the answer, but after many mistakes I can say you don’t want to end up in the position of having to reset the repo, uninstall git lfs, update your attributes, to reinstall git lfs and to reset your pointers. Why would I need to start all over? Because should your lfs pointers or files get corrupted (I won’t ask how because we can all agree that’s not important), you have no way of removing files from your large file storage. You can add all you want, but the lovely smart folks opted not to include a command for removing files or folders. So when using git lfs, be sure to follow the steps above because there is no going back once you start.

Leave a comment

Your email address will not be published. Required fields are marked *