Learn GitHub
$ gh ghadvancedgit.ghlfs

Large Files with Git LFS

4 learning objectives · 5 key terms · 4 commands · 1 diagrams · 5 quiz questions

$objectives

Large Files with Git LFS

Advanced Git

Module 3 of 5 · lesson 10 in this module

What you'll be able to do

  • Explain why large binaries break plain Git workflows
  • Track file patterns with Git LFS and .gitattributes
  • Migrate existing history containing large files
  • Diagnose quota, pointer, and smudge-filter failures
$concept

The idea, in plain language

Git stores every version of every file forever, which makes large binaries catastrophic: a 500MB dataset committed a few times balloons every clone, and history can never slim down without rewriting. Git LFS (Large File Storage) fixes this by storing tiny text pointers in the repository while the real bytes live on a separate LFS server, downloaded on demand.

Tracking is pattern-based (git lfs track "*.psd"), recorded in .gitattributes so the whole team shares it, and migration (git lfs migrate import) rewrites history to retroactively externalize files — with coordinated force-pushes, since rewritten history affects everyone. Quotas apply (bandwidth plus storage), pointers occasionally leak into working trees when filters misfire, and every CI runner needs LFS support — the operational price of binary-friendly Git.

$key terms

Key terms

Git LFS
An extension storing large-file contents outside the repository, referenced by pointers.
pointer file
The tiny text stub committed to Git describing the real object (oid + size).
.gitattributes
The file recording which patterns LFS tracks — shared by the whole team.
smudge/clean filters
The checkout/commit hooks swapping pointers for bytes and back.
migrate import
History-rewriting migration that externalizes already-committed large files.
$steps

How it works, step by step

  1. 1
    Install and initialize

    git lfs install sets up the smudge/clean filters globally once per machine; verify with git lfs version.

    installbash
    git lfs install
    git lfs version  # git-lfs/3.x
  2. 2
    Track patterns

    git lfs track "*.psd" records the pattern in .gitattributes — commit that file so teammates share tracking.

    trackbash
    git lfs track "*.psd"
    git add .gitattributes
    git lfs ls-files  # verify what is tracked
  3. 3
    Commit normally afterwards

    Once tracked, add and commit as usual — pointers enter Git, bytes upload to LFS on push.

    usebash
    git add assets/hero.psd
    git commit -m "Add hero artwork"
    git push
  4. 4
    Migrate existing history

    git lfs migrate import --include='*.zip' rewrites history to externalize past files — coordinate force-pushes with the whole team first.

    migratebash
    git lfs migrate import --include="*.zip" --everything
    git push --force  # everyone re-clones after this
$commands

Commands worth memorising

Every block below is copy-ready — use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what “working” looks like.

verify trackingbash
git lfs ls-files
Output
a1b2c3d4 * assets/hero.psd

Lists LFS-tracked files; empty output means nothing is actually tracked yet.

inspect storage usebash
git lfs du
Output
1.2 GB local, 0.8 GB remote

Local vs remote usage guides pruning and quota planning.

fetch all objectsbash
git lfs fetch --all
Output
(downloads every LFS object for offline work)

Shallow or filtered clones may lack objects; fetch explicitly before disconnecting.

prune old objectsbash
git lfs prune
Output
(removes local objects not on the current checkout)

Reclaims disk without affecting the remote or history.

$diagrams

Workflow diagrams

Diagram 1Pointers in Git, bytes in LFS

Tiny stubs version with code; bulk bytes travel separately on demand.

Reading the diagram
  1. Track patterns in .gitattributes and commit it.
  2. Commits store pointers; pushes upload bytes to LFS.
  3. Clones stay tiny; checkouts materialize needed versions.
$example

Worked example

Onboarding a design-heavy repository without cloning gigabytes.

taming a heavy repobash
git lfs track "*.psd" "*.zip"
git add .gitattributes && git commit -m "Track binaries with LFS"
git lfs ls-files
# a1b2c3d4 * assets/hero.psd
Output
Future clones stay small; designers push artwork without fear; CI fetches only what checkouts need.
1Tracking patterns cover the binary types before any gets committed normally.
2Committing .gitattributes shares the policy — teammates inherit tracking automatically.
3ls-files verifies real tracking; pointer stubs (not megabytes) enter history.
$use cases

Where you'll use it

▸Design assets, datasets, and binaries versioned beside code.
▸Keeping clone times sane on media-heavy repositories.
▸Migrating history that already contains committed binaries.
▸CI checkouts that fetch only the objects each job needs.
$mistakes

Common mistakes

  • Committing large files before tracking patterns exist (pointers never form).
  • Forgetting to commit .gitattributes, so teammates track nothing.
  • Rewriting history with migrate without coordinating force-pushes.
  • Assuming CI runners have LFS objects without fetching or enabling support.
$best practices

Best practices

  • Track binary patterns before the first binary commit.
  • Commit .gitattributes and review tracking changes like code.
  • Monitor bandwidth/storage quotas; prune local objects regularly.
  • Coordinate migrate-plus-force-push windows with the whole team.
  • Verify with ls-files — trust output, not assumptions.
$exercise

Hands-on exercise

LFS from zero to quota-aware

Track, migrate, and operate a binary-heavy practice repo.

  1. Create a practice repo, install LFS, and track *.bin before committing any.
  2. Commit binaries, push, and confirm ls-files plus small clone size.
  3. Commit one binary untracked, then migrate history to externalize it.
  4. Run du, fetch --all, and prune, noting local vs remote usage.
  5. Break a smudge filter deliberately (rename .gitattributes aside) and diagnose pointer text in the working tree.

💡 Hint: Pointer files start with version https://git-lfs.github.com/spec/v1 — seeing that text in a working file means filters misfired.

Done when: Tracked patterns, migrated history, quota awareness, and a diagnosed filter failure.

$quiz

Checkpoint quiz

0 of 5 answered · 0 correct

  1. Multiple choiceQ1

    What does Git actually store for an LFS-tracked file?

  2. Multiple choiceQ2

    Why must .gitattributes be committed?

  3. True or falseQ3

    True or false: migrating existing history with git lfs migrate requires coordinated force-pushes.

  4. TroubleshootingQ4

    A working file contains pointer text instead of image bytes. What failed?

  5. Multiple choiceQ5

    When should you prefer LFS over plain Git storage?

$summary

Module summary

  • LFS stores pointers in Git and bytes on a separate server.
  • Track patterns early via .gitattributes, committed and shared.
  • Migrate existing binaries with coordinated history rewrites.
  • Quotas, fetch state, and filter health need ongoing attention.
  • Pointer text in working files means materialization failed.

Next up: Big files handled; next is composing repositories from other repositories — submodules, subtrees, and worktrees.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.