🗄️ Git LFS: What it is, when you need it, and how to use it (before it's too late)

  

When working with Git, sooner or later you'll run into a major limitation: Git isn't designed to handle large files. Bloated repositories, incredibly slow clones, and unmanageable histories are common problems when versioning binary assets like images, videos, or design files.

That's where Git LFS (Large File Storage) comes in.

🔗 Do you like Techelopment? Check out the site for all the details!

A problem that often emerges too late

Many developers discover the existence of Git LFS in the worst way possible: when they try to upload a large file to GitHub for the first time.
The most common case is when attempting a git push that includes a file larger than 100 MB, the maximum size allowed by GitHub for normally versioned files.

At that point, GitHub rejects the push with an explicit error message, indicating that the file is too large. It's often only at this point—perhaps too late— that the developer discovers that Git exists, but isn't suitable for this type of content, and that there's a solution called Git LFS.

The problem is that, at this point, the file may have already been added to the repository's local history. This forces more complex interventions, such as rewriting Git history or migrating existing files to LFS, operations that could have been avoided with prior configuration.

Precisely for this reason, it's important to understand Git LFS before starting to version large assets: adopting it early allows you to avoid blocking errors, wasted time, and repositories that are difficult to maintain in the long run.

Tips & Tricks

Even if after deleting files larger than 100MB, the Git push continues to crash or give you an error, run this command to resolve the issue and continue working as before (but remember to remove large files and commit first 😉):

git reset origin/main

What is Git LFS

Git LFS is a Git extension designed to efficiently manage large or binary files.
Instead of saving these files directly in the Git repository, Git LFS:

  • keeps only a text pointer
  • stores the actual file in separate storage
  • downloads the actual content only when needed

From the user's perspective, the experience remains similar to traditional Git, but with lighter, more performant repositories.


When you need Git LFS

Git LFS is especially useful when your project includes:

  • High-resolution images (PNG, JPG, PSD)
  • Audio or video files
  • 3D models
  • Machine learning files (datasets, trained models)
  • Automatically generated binaries
  • Game assets

If you recognize any of these signs, Git LFS is probably the right choice:

  • The repository is growing rapidly in size
  • git clone or git fetch are very slow
  • Every change to a binary file saves a complete copy in the history
  • GitHub / GitLab report size limits

How Git LFS Works

The workflow is simple:

  1. Git LFS intercepts some user-configured file types (e.g., *.psd for all .psd files)
  2. Git saves a “pointer” file in the repository
  3. The actual file is uploaded to LFS storage
  4. Upon checkout, Git LFS automatically downloads the correct file

For the team, this is all transparent: the files open and edit normally.

Source https://git-lfs.com/

Installing Git LFS

First, install Git LFS:

git lfs install

This command configures Git to use LFS in your environment.


Tracking Files with Git LFS

To tell Git LFS which files to track, use the track command.

Example: Tracking all .psd files

git lfs track "*.psd"

This command updates (or creates) the .gitattributes file, which must be versioned in the repository:

git add .gitattributes
git commit -m "Add Git LFS for PSD files"

From now on, all .psd files will be managed by Git LFS.


Using Git LFS in your daily workflow

Once configured, the workflow remains unchanged:

git add large-file.psd
git commit -m "Update graphic asset"
git push

Git LFS will automatically upload the file to remote storage.
Anyone who clones the repository will receive the pointer, and the actual file will be downloaded at checkout.


Migrating Existing Files to Git LFS

If your repository already contains large, "normally" versioned files, you can migrate them:

git lfs migrate import --include="*.zip,*.psd"

⚠️ Warning: This command rewrites the repository's history, so it should be used with caution and coordinated with your team.


Limitations and Considerations

Before adopting Git LFS, it's good to know that:

  • Many services (GitHub, GitLab, Bitbucket) impose quotas Storage and Bandwidth
  • Git LFS is not ideal for files that change very frequently and infrequently (e.g., logs)
  • All team members must have Git LFS installed

Git LFS on GitHub and GitLab

The major Git platforms support Git LFS natively:

  • GitHub: Includes a free quota of storage and bandwidth
  • GitLab: Built-in support, with variable limits
  • Bitbucket: Dedicated plans for LFS

Always check your provider's limits to avoid unexpected crashes.


Conclusion

Git LFS is a tool Essential when Git alone isn't enough.
It allows you to:

  • maintain lightweight repositories
  • improve performance
  • correctly version large and binary files

If your project includes large assets, Git LFS isn't an option: it's a necessity.


Useful Links



Follow me #techelopment

Official site: www.techelopment.it
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
whatsapp: Techelopment
youtube: @techelopment