Terminal GuideTerminal Guide
git-lfs icon

Git LFS

Git Tools
macOSLinuxWindows
Go

Git extension for versioning large files.

Official Website

Features

Large File SupportPointer FilesBandwidth OptimizationGitHub/GitLab Support

Installation

Homebrew
brew install git-lfs
APT (Debian/Ubuntu)
apt install git-lfs
Pacman (Arch)
pacman -S git-lfs
Chocolatey
choco install git-lfs

Why 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

How Git LFS Works
=.repeat(50)
1. Configure Tracking
*.psd → Track with Git LFS
2. When running git add
Large file → Upload to LFS server
Repository → Store pointer file
3. Pointer File Contents
version https://git-lfs.github.com/spec/v1
oid sha256:4d7a214614...
size 1234567
4. When running git checkout
Pointer → Download actual file from LFS server

Git LFS stores large files on a separate server and keeps only lightweight pointers in the repository.

Installation

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 version

Basic Usage

1. Configure File Type Tracking

Tracking Configuration
# 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

Adding 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 main

3. Clone Repository

Clone
# 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 pull

Command List

Tracking Management

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 -l

Fetch and Pull Operations

Fetch & Pull
# 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 --recent

Information and Management

Info & 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-remote

Settings and Customization

.gitattributes Configuration Example

.gitattributes
# 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 -text

Git Configuration Customization

Git Configuration
# 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

ServiceFree TierAdditional Plans
GitHub1GB storage, 1GB/month bandwidth$5/month for 50GB additional
GitLab10GB (entire project)Varies by plan
Bitbucket1GB storage, 5GB/month bandwidthIncreased with paid plans
Azure DevOpsUnlimited (recommended under 50GB)-

Migrating Existing Repository

Migration
# 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=10MB

Warning:migrate import rewrites history, requiring coordination with all team members. After force push, everyone must re-clone the repository.

Tips

  • *Place .gitattributes at repository root and commit it first
  • *If LFS files needed in CI/CD, run git lfs install and git lfs pull
  • *Periodically delete unnecessary LFS files with git lfs prune to save disk space
  • *When pushing many LFS files, use git lfs push --all to ensure upload
  • *Use LFS file locking to prevent simultaneous editing of binary files: git lfs lock file.psd
  • *In GitHub Actions, use lfs: true option with actions/checkout

Official Resources

Written by Dai AokiPublished: 2026-01-20

Explore More