Git LFS
Git Large File Storage (LFS) replaces large files with lightweight pointers, storing actual file contents on a remote server. This keeps your repository fast and manageable.
What is Git LFS?
Git wasn't designed for large binary files. Every clone downloads the entire history, including all versions of every file. With large files, this becomes slow and wasteful.
Without LFS:
Repository contains full file history
Clone downloads ALL versions of large files
Size grows with every change
With LFS:
Repository contains small pointer files
Clone downloads only current versions
Large files stored separately on LFS serverKey points:
- Pointer files are tiny text files (~130 bytes)
- Actual content stored on LFS server
- Only needed versions are downloaded
- Works transparently after setup
When to Use Git LFS
Good Candidates for LFS
| File Type | Examples |
|---|---|
| Images | PSD, AI, PNG, JPG (large) |
| Audio | WAV, MP3, FLAC |
| Video | MP4, MOV, AVI |
| Archives | ZIP, TAR, 7z |
| Binaries | EXE, DLL, compiled assets |
| Data files | Large CSV, JSON, databases |
| Game assets | 3D models, textures, levels |
When NOT to Use LFS
- Small files - Overhead not worth it under ~100KB
- Text files - Git handles these efficiently
- Frequently diffed files - LFS doesn't show meaningful diffs
- Files that compress well - Git's compression may be enough
Requirements
Install Git LFS
brew install git-lfs
git lfs installServer Support
Most Git hosts support LFS:
- GitHub - Included, with storage limits
- GitLab - Included, configurable limits
- Bitbucket - Included with paid plans
- Azure DevOps - Included
Check your host's LFS storage limits and pricing.
Setup in Axis
Initialize LFS
- Open your repository
- Go to Repository menu
- Select LFS
- Click Initialize LFS (if not already set up)
This creates the .gitattributes file for tracking patterns.
Track File Types
- Open the LFS panel
- Click Add Pattern
- Enter a pattern (e.g.,
*.psd) - Click Add
Common patterns:
*.psd
*.ai
*.mp4
*.mov
*.zip
*.tar.gz
*.exe
*.dllTrack Specific Files
- Right-click a large file in staging
- Select Track with LFS
- File is added to
.gitattributes
Understanding .gitattributes
LFS tracking is configured in .gitattributes:
*.psd filter=lfs diff=lfs merge=lfs -text
*.mp4 filter=lfs diff=lfs merge=lfs -text
assets/large/** filter=lfs diff=lfs merge=lfs -textfilter=lfs- Use LFS for storagediff=lfs- Use LFS for diffsmerge=lfs- Use LFS for merges-text- Treat as binary
Working with LFS Files
Viewing LFS Files
The LFS panel shows:
- Tracked patterns - What file types use LFS
- LFS files - Files managed by LFS in your repo
- Download status - Which files are downloaded locally
Fetching LFS Files
LFS files are downloaded on demand:
- Automatic - Files download when checked out
- Manual fetch - Click Fetch LFS to download all
- Individual - Right-click a file to download it
Checking File Status
In the LFS panel, files show:
| Status | Meaning |
|---|---|
| Downloaded | File content available locally |
| Pointer only | Only pointer file, content on server |
| Modified | Local changes not yet committed |
Migrating Existing Files
Convert Files to LFS
If you have large files already in your repo:
- Track the pattern:
git lfs track "*.psd" - The existing files are automatically converted on next commit
- Previous history still contains full files
Rewrite History (Advanced)
To remove large files from entire history:
git lfs migrate import --include="*.psd" --everythingWARNING
This rewrites history. Only do this on repositories where you can force push and coordinate with all collaborators.
LFS and Cloning
Clone with LFS
Cloning an LFS repository:
- Clone downloads repository with pointer files
- LFS files download based on checkout
- Use
git lfs pullto ensure all files downloaded
Shallow Clone
For faster clones:
git clone --depth 1 <url>This gets only latest versions, minimal LFS downloads.
Skip LFS on Clone
If you don't need LFS files:
GIT_LFS_SKIP_SMUDGE=1 git clone <url>Files remain as pointers until manually fetched.
Best Practices
Track Early
Set up LFS tracking before adding large files. Retroactive conversion is more complex.
Use Patterns
Track by extension rather than individual files:
# Good
*.psd
# Avoid (unless necessary)
assets/logo.psdDocument LFS Usage
Add to your README:
## Large Files
This repository uses Git LFS for large assets.
Install Git LFS before cloning: https://git-lfs.github.ioMonitor Storage
Track your LFS storage usage on your Git host. Large files add up quickly.
Clean Up Unused Files
LFS files count against storage even after deletion. Use git lfs prune to clean up:
# Remove old LFS files not in recent commits
git lfs pruneTroubleshooting
"Smudge filter lfs failed"
LFS isn't installed or configured:
git lfs install
git lfs pullLarge Clone Size
LFS files downloading during clone. For faster clone:
GIT_LFS_SKIP_SMUDGE=1 git clone <url>
cd repo
git lfs pullFile Shows as Pointer
The LFS content wasn't downloaded:
git lfs pull
# Or for specific file:
git lfs pull --include="path/to/file"Storage Limit Reached
Your Git host's LFS storage is full:
- Check storage usage on host
- Delete unused LFS files
- Run
git lfs prune - Consider upgrading plan
LFS vs Alternatives
| Solution | Best For |
|---|---|
| Git LFS | Large files that change occasionally |
| Git submodules | Separate repositories for assets |
| External storage | Very large files, CDN delivery |
| git-annex | Scientific data, flexible backends |
