Git‑LFS: Why Binary Files Need a Special Treatment
Git was designed for text‑based source code.
When you add large binaries (images, videos, compiled artifacts) to a repo, several problems arise:
- Repository bloat: Every version of a binary is stored in the repo, making the clone size huge.
- Performance hit: Operations like
git clone, git fetch and git status become slower.
- Disk space waste: Binaries are often binary‑identical between commits; Git still keeps a copy each time.
- Network traffic: Team members download the full binary each time, even when only metadata changes.
Git‑LFS (Large File Storage) addresses these issues by replacing binaries with lightweight pointers in the repo.
Git‑LFS – A Quick Overview
- Extension that lets you store large files outside the Git repository.
- In the repo you keep a tiny pointer file (~100 bytes).
- The actual binary is stored on a dedicated LFS server (e.g., GitHub LFS, GitLab LFS, or self‑hosted).
- Git‑LFS works transparently – you continue using normal
git add/commit/push commands.
Benefit snapshot:
- Repo size stays small.
- Clones and pulls are faster.
- Bandwidth usage is minimized.
When to Apply Git‑LFS
- Large assets: images > 100 KB, audio/video, PDFs, compiled binaries.
- Frequent updates: assets that change often but are large.
- Multiple contributors: teams that clone and pull regularly.
- CI/CD pipelines: need fast artifact fetches.
**Rule of thumb:** If a file grows > 50 MB or you hit > 1 GB repo size, consider Git‑LFS.
Core Git‑LFS Concepts
- Pointer file: a tiny text file that lives in Git, containing a hash and the file size.
- Object storage: binary content stored in an LFS server with a unique ID (SHA‑256).
- Transfer hooks: Git‑LFS runs pre‑push and post‑fetch hooks to upload/download binaries.
- .gitattributes: file patterns to tell Git‑LFS which files to track.
# Example .gitattributes entry
assets/*.png filter=lfs diff=lfs merge=lfs -text
Installation Steps
- Install Git‑LFS on your machine (see Git‑LFS website).
- Initialize in your repository:
git lfs install
- Track the file types you need:
git lfs track "*.png"
git lfs track "*.mp4"
- Commit the new
.gitattributes file:
git add .gitattributes
git commit -m "Track large assets with Git‑LFS"
Typical Workflow with Git‑LFS
- Add and commit as usual; Git‑LFS replaces the binary with a pointer.
- Push to remote: Git‑LFS uploads the actual binary to the LFS server.
- Clone/fetch/pull: Git‑LFS automatically downloads the binaries when you get a commit.
- Git commands (
diff, status) work normally; LFS hides the complexity.
All this is handled by the git lfs helper installed earlier.
How Data Is Saved & Transferred
Local Commit
- Write file → Git‑LFS hook creates a pointer file (small text). The real file is stored locally in
~/.git/lfs/objects.
- Pointer is added to Git index; commit stores only the pointer.
Push
- Git‑LFS runs
post-push hook.
- All new objects in
~/.git/lfs/objects are uploaded via HTTP(S) to the LFS endpoint.
- Server stores objects in a content‑addressable store.
Clone/Fetch
- Git receives pointers.
- Git‑LFS runs
post-fetch hook to download binary objects from the LFS server.
- Files are restored to the working tree.
Result: the Git history stays tiny; only the binary data lives on the LFS server.
Pros & Cons of Git‑LFS
| Pros | Cons |
| Smaller repo size |
Requires a separate LFS server or hosting plan (GitHub LFS has bandwidth limits) |
| Faster clones & pulls |
Additional overhead during push (upload to LFS) |
| Works with existing Git workflow |
Complexity for beginners (install & configure hooks) |
| Large binary support (e.g., game assets, machine‑learning weights) |
Potential storage cost on hosted services |
References & Further Reading
Takeaway & Next Steps
- Large binaries are a performance hazard for Git. Git‑LFS solves it.
- Setup is straightforward:
git lfs install + git lfs track.
- Make sure to commit the
.gitattributes file and share it with teammates.
- Monitor your LFS usage on your hosting provider; set quotas if necessary.
- Test by cloning a fresh copy and verifying that binaries appear correctly.
Ready to keep your repo lean and your team fast? Start adding Git‑LFS today!