Skip to content

Git LFS: Managing Large Files in Git Repositories

DodaTech Updated 2026-06-22 5 min read

In this tutorial, you'll learn about Git LFS: Managing Large Files in Git Repositories. We cover key concepts, practical examples, and best practices.

Git LFS replaces large files with small pointer files and stores actual content on a remote server, keeping your repository small and cloning fast.

In this tutorial, you'll learn Git Large File Storage (LFS) for managing binary files, assets, and datasets in Git repositories. Standard Git stores every version of every file in history, making it inefficient for large files. LFS replaces large files with text pointers and stores the actual content on a remote server. By the end, you'll set up LFS, migrate existing repositories, and manage bandwidth limits.

flowchart LR
  A[Large file added] --> B[Git LFS intercepts]
  B --> C[Pointer file committed to Git]
  B --> D[Actual file uploaded to LFS store]
  C --> E[git push]
  E --> F[GitHub/GitLab]
  D --> F
  F --> G[git clone]
  G --> H[Pointer file downloaded]
  H --> I[Git LFS downloads actual file]

Installing Git LFS

# Install LFS
sudo apt install git-lfs
# or brew install git-lfs

# Initialize LFS (one-time per user)
git lfs install

# Verify installation
git lfs version

Expected output:

git-lfs/3.4.0 (GitHub; linux amd64; go 1.21)

Setting Up LFS in a Repository

cd your-repo
git lfs track "*.psd"
git lfs track "*.zip"
git lfs track "*.mp4"
git lfs track "assets/**"

Expected output after tracking:

Tracking "*.psd"
Tracking "*.zip"
Tracking "*.mp4"
Tracking "assets/**"

This creates a .gitattributes file:

*.psd filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.mp4 filter=lfs diff=lfs merge=lfs -text
assets/** filter=lfs diff=lfs merge=lfs -text

Migrating Existing Files to LFS

If you already have large files committed without LFS, migrate them:

git lfs migrate import --include="*.psd,*.zip" --everything

Expected output:

migrate: Sorting commits: done, 50 commits
migrate: Rewriting commits: 100% (50/50), done
migrate: Updating refs: done

This rewrites history to move the matching files to LFS. Warning: This changes commit hashes and requires force-pushing.

Working with LFS Files

LFS files behave like normal files in your working directory:

# Add large files normally
echo "binary content" > large-file.zip
git add large-file.zip
git commit -m "Add large file"
git push

During clone or pull:

git clone repo-url
# LFS files are downloaded automatically

Or fetch LFS files later:

git lfs pull

LFS File Locking

LFS supports file locking to prevent merge conflicts on binary files:

# Lock a file
git lfs lock assets/logo.psd

# List locks
git lfs locks

# Unlock a file
git lfs unlock assets/logo.psd

# Unlock another user's file (if allowed)
git lfs unlock --force assets/logo.psd

File locking ensures that only one person edits a binary file at a time, preventing unresolvable merge conflicts.

LFS Bandwidth and Storage

GitHub and GitLab impose LFS storage limits:

Platform Free Storage Bandwidth
GitHub 1 GB 1 GB/month
GitLab 5 GB Varies by plan
Bitbucket 1 GB 1 GB/month

Check your LFS usage:

git lfs ls-files --all
git lfs status

Common Errors

Error Cause Fix
git lfs: command not found LFS not installed Install git-lfs package
This repository is over its data quota Exceeded bandwidth Upgrade plan or remove large files
Pointer file not updated LFS filter not configured Re-run git lfs install
Smudge error: file too large Single file exceeds LFS limit Split file or reduce size
batch response: Repository cannot accept new objects Storage full Free up space or upgrade
git lfs migrate rewrites history Commit hashes change Coordinate with team before force-push
LFS object not found on fetch Object missing from server Re-upload with git lfs push --all

Practice Questions

What is Git LFS?

Git LFS (Large File Storage) is a Git extension that replaces large files with text pointers and stores the actual file content on a remote server. This keeps your repository small and cloning fast while still tracking binary files in version control.

When should I use Git LFS?

Use LFS for files that change frequently and are too large for regular Git: binary assets (PSD, AI), media files (MP4, WAV), datasets (CSV, Parquet), firmware images, and game assets. A good threshold is files over 5-10 MB.

What happens when I clone a repo with LFS files?

Git LFS intercepts the checkout and downloads the actual file content from the LFS server. The pointer file stored in Git is replaced with the real file in your working directory. This happens automatically if LFS is installed and configured.

Can I use Git LFS on GitHub?

Yes. GitHub supports LFS with a 1 GB free storage limit and 1 GB monthly bandwidth. Larger limits are available on paid plans. GitHub also supports LFS objects in Actions and Dependabot.

How do I migrate existing large files to LFS?

Use git lfs migrate import --include="*.psd,*.zip" --everything. This rewrites history to replace large files with LFS pointers. Note that rewriting history changes all commit hashes, so coordinate with your team and use --force push

Challenge

Create a repository, add a large file (create a 15 MB dummy file with dd if=/dev/zero of=large.dat bs=1M count=15), commit it, and note the repository size. Convert the file to LFS using git lfs migrate import. Compare repository sizes before and after. Verify the LFS pointer file is small by examining it with cat large.dat.

Real-World Task

You have a repository with 2 GB of design assets (PSD files, PNGs, and videos) committed without LFS. Use git lfs migrate to move the PSD and video files to LFS while keeping PNGs in regular Git (if they are small). Set up .gitattributes for future files. Force-push the rewritten history. Configure CI/CD to install LFS before builds. This migration pattern is used at DodaTech for DodaZIP's marketing site assets.


Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro