Large Files with Git LFS
4 learning objectives · 5 key terms · 4 commands · 1 diagrams · 5 quiz questions
Large Files with Git LFS
Advanced GitWhat you'll be able to do
- Explain why large binaries break plain Git workflows
- Track file patterns with Git LFS and .gitattributes
- Migrate existing history containing large files
- Diagnose quota, pointer, and smudge-filter failures
The idea, in plain language
Git stores every version of every file forever, which makes large binaries catastrophic: a 500MB dataset committed a few times balloons every clone, and history can never slim down without rewriting. Git LFS (Large File Storage) fixes this by storing tiny text pointers in the repository while the real bytes live on a separate LFS server, downloaded on demand.
Tracking is pattern-based (git lfs track "*.psd"), recorded in .gitattributes so the whole team shares it, and migration (git lfs migrate import) rewrites history to retroactively externalize files — with coordinated force-pushes, since rewritten history affects everyone. Quotas apply (bandwidth plus storage), pointers occasionally leak into working trees when filters misfire, and every CI runner needs LFS support — the operational price of binary-friendly Git.
Key terms
- Git LFS
- An extension storing large-file contents outside the repository, referenced by pointers.
- pointer file
- The tiny text stub committed to Git describing the real object (oid + size).
- .gitattributes
- The file recording which patterns LFS tracks — shared by the whole team.
- smudge/clean filters
- The checkout/commit hooks swapping pointers for bytes and back.
- migrate import
- History-rewriting migration that externalizes already-committed large files.
How it works, step by step
- 1Install and initialize
git lfs install sets up the smudge/clean filters globally once per machine; verify with git lfs version.
installbashgit lfs install git lfs version # git-lfs/3.x - 2Track patterns
git lfs track "*.psd" records the pattern in .gitattributes — commit that file so teammates share tracking.
trackbashgit lfs track "*.psd" git add .gitattributes git lfs ls-files # verify what is tracked
- 3Commit normally afterwards
Once tracked, add and commit as usual — pointers enter Git, bytes upload to LFS on push.
usebashgit add assets/hero.psd git commit -m "Add hero artwork" git push
- 4Migrate existing history
git lfs migrate import --include='*.zip' rewrites history to externalize past files — coordinate force-pushes with the whole team first.
migratebashgit lfs migrate import --include="*.zip" --everything git push --force # everyone re-clones after this
Commands worth memorising
Every block below is copy-ready — use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what “working” looks like.
git lfs ls-filesa1b2c3d4 * assets/hero.psd
Lists LFS-tracked files; empty output means nothing is actually tracked yet.
git lfs du
1.2 GB local, 0.8 GB remote
Local vs remote usage guides pruning and quota planning.
git lfs fetch --all(downloads every LFS object for offline work)
Shallow or filtered clones may lack objects; fetch explicitly before disconnecting.
git lfs prune
(removes local objects not on the current checkout)
Reclaims disk without affecting the remote or history.
Workflow diagrams
| Without LFS | With LFS | |
|---|---|---|
| 500MB file in history | Every clone downloads 500MB+ forever | Clone downloads a 130-byte pointer |
| Three versions | 1.5GB in every clone | Bytes fetched per version on demand |
| CI checkout | Minutes of downloading | Seconds; fetch extras only if needed |
Tiny stubs version with code; bulk bytes travel separately on demand.
- Track patterns in .gitattributes and commit it.
- Commits store pointers; pushes upload bytes to LFS.
- Clones stay tiny; checkouts materialize needed versions.
Worked example
Onboarding a design-heavy repository without cloning gigabytes.
git lfs track "*.psd" "*.zip" git add .gitattributes && git commit -m "Track binaries with LFS" git lfs ls-files # a1b2c3d4 * assets/hero.psd
Future clones stay small; designers push artwork without fear; CI fetches only what checkouts need.
Where you'll use it
Common mistakes
- Committing large files before tracking patterns exist (pointers never form).
- Forgetting to commit .gitattributes, so teammates track nothing.
- Rewriting history with migrate without coordinating force-pushes.
- Assuming CI runners have LFS objects without fetching or enabling support.
Best practices
- Track binary patterns before the first binary commit.
- Commit .gitattributes and review tracking changes like code.
- Monitor bandwidth/storage quotas; prune local objects regularly.
- Coordinate migrate-plus-force-push windows with the whole team.
- Verify with ls-files — trust output, not assumptions.
Hands-on exercise
LFS from zero to quota-aware
Track, migrate, and operate a binary-heavy practice repo.
- Create a practice repo, install LFS, and track *.bin before committing any.
- Commit binaries, push, and confirm ls-files plus small clone size.
- Commit one binary untracked, then migrate history to externalize it.
- Run du, fetch --all, and prune, noting local vs remote usage.
- Break a smudge filter deliberately (rename .gitattributes aside) and diagnose pointer text in the working tree.
💡 Hint: Pointer files start with version https://git-lfs.github.com/spec/v1 — seeing that text in a working file means filters misfired.
Done when: Tracked patterns, migrated history, quota awareness, and a diagnosed filter failure.
Checkpoint quiz
0 of 5 answered · 0 correct
- Multiple choiceQ1
What does Git actually store for an LFS-tracked file?
- Multiple choiceQ2
Why must .gitattributes be committed?
- True or falseQ3
True or false: migrating existing history with git lfs migrate requires coordinated force-pushes.
- TroubleshootingQ4
A working file contains pointer text instead of image bytes. What failed?
- Multiple choiceQ5
When should you prefer LFS over plain Git storage?
Module summary
- LFS stores pointers in Git and bytes on a separate server.
- Track patterns early via .gitattributes, committed and shared.
- Migrate existing binaries with coordinated history rewrites.
- Quotas, fetch state, and filter health need ongoing attention.
- Pointer text in working files means materialization failed.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.