How to Remove Git LFS from Your Repo

Posted by Ryan Gittings

Hey there! If you’re working with Netlify, you might have heard the news: Netlify Large Media is being phased out. And with that, it’s time to say goodbye to Git Large File Storage (Git LFS) for my projects. Don’t worry; I'm here to guide you through this change smoothly. Let’s walk through how you can remove Git LFS from your repo and handle those large files in a new, efficient way.

What’s Git LFS and Why the Change?

First, a quick recap: Git LFS helps manage large files by storing them outside your repo and using pointers instead. This made things easy, especially with Netlify Large Media taking care of the heavy lifting. But as Netlify evolves, they’re moving away from this setup. So, it’s time to adapt and embrace new ways to handle your big files.

Steps to Remove Git LFS

We’ll keep this simple and straightforward (this is actually a post for me to reference too)...

1. Find Out What’s Tracked by Git LFS

Let’s start by seeing which files are using Git LFS. Just pop this command in your terminal:

git lfs ls-files

You’ll get a list of all the files tracked by Git LFS.

2. Get All Your LFS Files

Next, make sure you have all your large files checked out. Here’s how:

git lfs fetch --all
git lfs checkout

This makes sure you have everything you need before we make changes.

3. Clean Up Git Configurations

Let’s tidy up and remove LFS filters from your Git setup:

git lfs uninstall

Or you can manually remove LFS settings from your .git/config file.

4. Switch LFS Files to Regular Git Files

Now, let’s convert those LFS files back to regular files. Open your .gitattributes file and remove the lines that tell Git to use LFS for certain files. Look for lines like this and delete them:

*.png filter=lfs diff=lfs merge=lfs -text

Then manually remove the tracked entries (re-run this command for every .gitattributes entry):

git lfs untrack '*.png'

Then run:

git add --renormalize .

5. Push Your Changes

You’re almost there! Commit your changes and push them back to your remote repository:

git commit -m "Switched from Git LFS to regular Git files"
git push origin main

Moving Forward with Large Files

1. Use Netlify Image CDN (Easiest)

You can use Netlify Image CDN to transform images on demand. This works similar to Large Media and is very easy to enable/disable.

2. Use 11ty Image (Or Similar)

Using a tool that performs build-time image transformations gives you full control and some local dev benefits too! I personally use 11ty Image for optimisation, as it handles file format, compressions, SVG formats and advanced caching.

Wrapping It Up

Removing Git LFS might seem like a big change, but it’s just another step in our journey to keep things running smoothly. By following these steps, you’ll transition away from Git LFS without a hitch. Plus, you’ll be all set up with modern ways to manage your big files.

FAQs

What happens to my LFS files after I remove Git LFS?

They get converted to regular Git files, and you can keep using them just like before. Just make sure to push those changes to your remote repo.

Can I still use Git LFS even if Netlify Large Media is gone?

Sure thing! You can still use Git LFS, but for deployments, you’ll want to handle big files through other means.

Will removing Git LFS affect my repo’s performance?

It might make your repo larger, but using external storage or CDNs can help keep things running smoothly.

And there you have it! With these steps, you’re all set to handle large files in a fresh, new way. Embrace the change, and happy coding!