Standard Git repositories track file differences line-by-line, which works brilliantly for plaintext source code but causes severe performance issues when applied to multi-megabyte binary assets. Storing large video files, 3D graphics models, game audio packs, or machine learning datasets directly in Git leads to massive repository bloat, causing clone and pull operations to slow down dramatically. Git Large File Storage (Git LFS) resolves this challenge by replacing large binary assets with lightweight text pointer files inside the repository, storing the actual raw payloads on dedicated remote storage servers.
How Git LFS Works Under the Hood
Git LFS operates seamlessly alongside your standard Git workflow:
- Text Pointer Files: When you commit a tracked large file, Git LFS calculates its SHA-256 cryptographic hash and stores a small metadata pointer (around 130 bytes) inside the Git tree.
- Dedicated LFS Server Storage: The large binary payload is transferred separately via HTTP/HTTPS to an LFS-compatible host (such as GitHub, GitLab, or Bitbucket).
- Lazy Downloading: When teammates clone the repository, they download the lightweight pointers instantly. Full binary files are only fetched for the specific branch or commit currently checked out.
- Seamless User Experience: To developers, files appear and behave like normal files on disk; Git filters swap pointers for binaries automatically during checkout and commit.
How to Install Git LFS on Linux
Git LFS is available across all major Linux package managers:
| Linux Distribution | Terminal Installation Command |
|---|---|
| Ubuntu / Debian | sudo apt update && sudo apt install git-lfs |
| Arch Linux / Manjaro | sudo pacman -S git-lfs |
| Fedora / RHEL | sudo dnf install git-lfs |
| Alpine Linux | sudo apk add git-lfs |
After installing the binary, initialise the global Git LFS filter hooks on your system once:
git lfs install
This command registers the necessary clean and smudge filters in your global ~/.gitconfig.
Configuring Git LFS in a Repository
To configure Git LFS for a software project, navigate into your local repository root:
- Choose the file extensions or directory paths you wish to track via LFS:
git lfs track "*.zip" git lfs track "*.mp4" git lfs track "*.onnx" git lfs track "models/**" - Git LFS generates or updates a configuration file named
.gitattributesin the repository root. - Commit the
.gitattributesfile to ensure your tracking rules are enforced across all team members:git add .gitattributes git commit -m "Configure Git LFS tracking patterns" - Add and commit your actual large assets normally:
git add models/weights.onnx git commit -m "Add pre-trained model weights" git push origin main
Verifying and Auditing Tracked LFS Assets
To confirm that files are tracked via LFS rather than standard Git blobs:
| Command | Purpose |
|---|---|
git lfs ls-files |
Lists all assets in the current commit managed by Git LFS along with their SHA hashes. |
git lfs status |
Displays staged large files pending commit and verification. |
git lfs pull |
Manually pulls and checks out all missing LFS binary assets for the current branch. |
git lfs prune |
Deletes old local LFS binaries from .git/lfs/objects to reclaim disk space. |
Migrating Existing Repositories to Git LFS
If a legacy repository has already accumulated gigabytes of binary history, run the built-in migration utility to rewrite past commits:
git lfs migrate import --include="*.psd,*.mp4" --everything
This command sweeps through past repository commits, retroactively converts existing binaries into lightweight LFS pointers, and dramatically shrinks overall clone times for the entire development team.