Theory
Theory: The Index is a Filter; LFS is a Pointer
Git will store any blob you add. Ignore rules and attributes are policy on what enters the index and how it is treated. LFS replaces a large blob with a tiny pointer blob and puts the real bytes elsewhere.
Invariants
.gitignoreapplies to untracked files. A tracked file stays tracked untilgit rm --cached.- Precedence: command-line exclude →
.git/info/exclude→.gitignorein-tree → global excludes file. gitattributesattach behavior to paths: text vs binary,eol,diff,merge,filter(clean/smudge).- Git LFS stores a pointer file (text, few hundred bytes) in Git, and the payload in an LFS object store the forge must provide.
git add huge.bin without LFS blob of huge.bin in .git/objects
git add huge.bin with LFS blob of pointer version https://git-lfs...
payload ──► LFS store (not in packfiles)
Why Git is a bad backup of videos
Every clone downloads every version of every blob (unless partial clone / LFS / sparse). A 200 MB binary edited ten times is ~2 GB of packfile. LFS and “do not commit build output” are the same theory: Git’s object store is for source, not for arbitrary bytes.
What can break
- Ignoring
.envafter it was committed (mustrm --cached). - CRLF filters on a Linux-only repo.
- Pushing LFS pointers to a forge with no LFS storage; clones get pointers, not files.
How to read this chapter
Patterns, attributes, archive, LFS, then a lab. Platform chapters later must store LFS if you use it.