Git LFS
Git LFS stores large files outside the main object database, keeping repos fast for code and version-controlling assets without bloating clones.
Git LFS - hands on
EXAMPLE
# Install # macOS: brew install git-lfs # Ubuntu: apt install git-lfs # Windows: comes with Git for Windows # Per-user one-time git lfs install # In your repo, track patterns cd my-app git lfs track '*.psd' git lfs track '*.mp4' git lfs track 'assets/raw/*.png' # This writes/updates .gitattributes - commit it git add .gitattributes git commit -m 'Track psd, mp4, raw png with LFS' # Add a large file like normal cp ~/Downloads/hero.psd assets/ git add assets/hero.psd git commit -m 'Add hero artwork' git push # Clone gets pointers + downloads on checkout git clone https://example.com/my-app # git smudge filter pulls the actual file from LFS storage on checkout # Check what's tracked git lfs ls-files # Move history to LFS retroactively (DANGEROUS - rewrites history) git lfs migrate import --include='*.psd' --everything # Force push, coordinate with all clones, delete and re-clone forks # Pruning local cache git lfs prune # remove old, unreferenced LFS objects # CI considerations # - Cache .git/lfs between builds # - Use partial clones if you only need code: git clone --filter=blob:none --no-checkout REPO git checkout HEAD # pulls only needed blobs # Storage and bandwidth # - GitHub LFS quota is small by default; check your plan # - Self-hosted: gitea, gitlab, or LFS test server
Why it matters
Use LFS for things git was not designed for - PSDs, video, ML weights, raw images. Resist tracking your entire assets/ tree; only the binaries that grow large or change often. Migrating history retroactively is painful, so do it deliberately and announce to your team.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
git lfs install git lfs track '*.psd' # Large file pointers in repo, real data on the LFS server.Try it Yourself »
Discussion
Loading…