Skip to content

Git LFS Quick Recipes

One-page command reference for Git LFS setup, selective CI downloads, file locking, and cache maintenance.


1. Fast CI checkout with selective download

# Clone with pointer files only (no binary payload download)
export GIT_LFS_SKIP_SMUDGE=1
git clone --depth 1 <REPO_URL> workspace
cd workspace

# Pull only required subdirectories or asset types
git lfs pull --include="tests/fixtures/**"
git lfs pull --exclude="models/checkpoints/**"

2. Track new binary patterns

# Register LFS filters in local repository
git lfs install

# Track file extensions
git lfs track "*.tar.gz" "*.parquet" "*.onnx" "assets/binaries/**"

# Persist and commit tracking definitions
git add .gitattributes
git commit -m "chore(lfs): track binary assets with Git LFS"

3. Lock unmergeable binary files

# Mark pattern as lockable in .gitattributes
echo "*.psd filter=lfs diff=lfs merge=lfs -text lockable" >> .gitattributes

# Acquire exclusive lock before editing
git lfs lock design/mockups.psd

# View all active repository locks
git lfs locks

# Unlock after pushing commit
git lfs unlock design/mockups.psd

4. Rewrite history to migrate large files

# Audit large historical files
git lfs migrate info --top=10

# Convert past commits across all branches to LFS pointers
git lfs migrate import --include="*.iso,*.bin,*.onnx" --everything

# Push sanitized history
git push --force --all
git push --force --tags

5. Local cache cleanup and verification

# Preview reclaimable disk space
git lfs prune --dry-run

# Delete cached objects verified on remote server
git lfs prune --verify-remote

# Verify pointer file integrity in working tree
git lfs fsck