Home

Use git-lfs on File Already Committed

Using Git LFS on a file that is already being track without it requires an extra step.

I ran into an issue where I wanted to use Git Large File Storage on a file I had already committed to a repository without using git-lfs.

Let's say my file is some beefy design file that I saved to design/mockups.sketch.

Setup Git LFS

If you haven't already setup your repo to use git-lfs, that's where you should start. Tell Git you want to use LFS to track this file:

$ git lfs track desgin/mockups.sketch

This will place a .gitattributes file in your repo (if you didn't already have one). Commit this file:

$ git add .gitattributes
$ git commit -m "Use lfs on design mockups"

Track Already-Committed File

If you look at what LFS is currently tracking, it doesn't give you any feedback:

$ git lfs ls-files

That's because it's not tracking anything yet.

What we need to do is remove the file from Git's cache, then recommit it:

$ git rm --cached design/mockups.sketch
$ git add design/mockups.sketch
$ git commit -m "Begin tracking mockups with lfs"

And now if we look at what LFS is tracking, we see the file:

$ git lfs ls-files
036310e243 - design/mockups.sketch

References:

Let's Connect

Keep Reading

Is GitHub the Best CMS?

It seems like a silly question, given that GitHub is not typically thought about as a CMS. But I analyze the question anyways, using a series of 11 factors.

Aug 30, 2022

Git: Set Default Branch to "main" on "init"

Tired of remembering to rename the master branch after running git init? This option will help you!

Mar 18, 2021

Squash all Commits into a Single Commit

Sometimes it makes sense to start over in Git's history while maintaining the current state of your code.

Dec 09, 2014