Git LFS
Git extension for versioning large files.
Official WebsiteFeatures
Installation
brew install git-lfsapt install git-lfspacman -S git-lfschoco install git-lfsWhy Use Git LFS?
Git LFS (Large File Storage) is an extension for efficiently managing large files in Git repositories. Manage images, videos, datasets, binary files, and more without bloating repository size.
Large File Support
Manage files exceeding GitHub's 100MB limit, including images, videos, audio, 3D models, and datasets.
Pointer File Method
Store lightweight pointers instead of actual files. Dramatically reduce download size during cloning.
Bandwidth Optimization
Download only needed files. Retrieve only current branch files during checkout.
Version Control
Large files support Git history management. Access previous versions.
How It Works
Git LFS stores large files on a separate server and keeps only lightweight pointers in the repository.
Installation
# macOS (Homebrew)
brew install git-lfs
# Ubuntu/Debian
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
# Windows (Chocolatey)
choco install git-lfs
# Windows (Winget)
winget install GitHub.GitLFS
# Fedora
sudo dnf install git-lfs
# Enable Git LFS (run once after installation)
git lfs install
# Check version
git lfs versionBasic Usage
1. Configure File Type Tracking
# Track specific extensions with LFS
git lfs track "*.psd"
git lfs track "*.png"
git lfs track "*.mp4"
git lfs track "*.zip"
# Files in specific directories
git lfs track "assets/**"
git lfs track "data/*.csv"
# .gitattributes is automatically created/updated
cat .gitattributes
# *.psd filter=lfs diff=lfs merge=lfs -text
# *.png filter=lfs diff=lfs merge=lfs -text
# Important: Commit .gitattributes
git add .gitattributes
git commit -m "Track large files with Git LFS"2. Add and Commit Files
# Add files as usual
git add design.psd
git add video.mp4
# Commit (LFS automatically processes files)
git commit -m "Add design files"
# Push (large files upload to LFS server)
git push origin main3. Clone Repository
# Normal clone (LFS files automatically download)
git clone https://github.com/user/repo.git
# Clone without LFS files
GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/user/repo.git
# Download LFS files later
git lfs pullCommand List
Tracking Management
# Check tracked patterns
git lfs track
# Untrack
git lfs untrack "*.psd"
# List files managed by LFS
git lfs ls-files
# Show with detailed info
git lfs ls-files -lFetch and Pull Operations
# Download LFS files
git lfs pull
# Download specific files only
git lfs pull --include="*.png"
# Exclude specific files
git lfs pull --exclude="*.mp4"
# Fetch LFS objects from remote (download only)
git lfs fetch
# Fetch LFS objects for all branches
git lfs fetch --all
# Fetch LFS objects for recent commits
git lfs fetch --recentInformation and Management
# Check LFS status
git lfs status
# Show LFS object info
git lfs env
# Check local cache size
git lfs prune --dry-run
# Delete unnecessary local cache
git lfs prune
# Delete old LFS files (unreferenced)
git lfs prune --verify-remoteSettings and Customization
.gitattributes Configuration Example
# Image files
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text
*.ai filter=lfs diff=lfs merge=lfs -text
# Video & audio files
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.mov filter=lfs diff=lfs merge=lfs -text
*.avi filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
# Compressed files
*.zip filter=lfs diff=lfs merge=lfs -text
*.tar.gz filter=lfs diff=lfs merge=lfs -text
*.7z filter=lfs diff=lfs merge=lfs -text
# Data files
*.csv filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
# 3D models
*.fbx filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text
# Fonts
*.woff filter=lfs diff=lfs merge=lfs -text
*.woff2 filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -textGit Configuration Customization
# Set LFS parallel download count
git config --global lfs.concurrenttransfers 8
# Bandwidth limit (bytes/sec)
git config --global lfs.activitytimeout 60
# Custom LFS server configuration
git config lfs.url "https://your-lfs-server.com"
# LFS server for specific remote
git config remote.origin.lfsurl "https://your-lfs-server.com"
# Change LFS cache location
git config --global lfs.storage "/path/to/lfs/storage"Hosting Service Support
| Service | Free Tier | Additional Plans |
|---|---|---|
| GitHub | 1GB storage, 1GB/month bandwidth | $5/month for 50GB additional |
| GitLab | 10GB (entire project) | Varies by plan |
| Bitbucket | 1GB storage, 5GB/month bandwidth | Increased with paid plans |
| Azure DevOps | Unlimited (recommended under 50GB) | - |
Migrating Existing Repository
# Migrate existing files to LFS
git lfs migrate import --include="*.psd,*.png,*.mp4" --everything
# Migrate specific branches only
git lfs migrate import --include="*.psd" --include-ref=refs/heads/main
# Rewrite entire history (force push required)
git lfs migrate import --include="*.psd" --everything
git push --force-with-lease origin main
# Dry run (no actual changes)
git lfs migrate info --include="*.psd"
# Check size reduction from migration
git lfs migrate info --above=10MBWarning:migrate import rewrites history, requiring coordination with all team members. After force push, everyone must re-clone the repository.
Tips
- *Place
.gitattributesat repository root and commit it first - *If LFS files needed in CI/CD, run
git lfs installandgit lfs pull - *Periodically delete unnecessary LFS files with
git lfs pruneto save disk space - *When pushing many LFS files, use
git lfs push --allto ensure upload - *Use LFS file locking to prevent simultaneous editing of binary files:
git lfs lock file.psd - *In GitHub Actions, use
lfs: trueoption withactions/checkout
Official Resources
- Official Website: https://git-lfs.com/
- GitHub: https://github.com/git-lfs/git-lfs
- Documentation: https://github.com/git-lfs/git-lfs/wiki