Sub topic 1
Versioning Large Binary Files with Git LFS
Prerequisites
This chapter assumes you know basic Git commands such as clone, add, commit, push, and pull. You should also understand branches, remotes, .gitignore, and .gitattributes.
Why Large Binary Files Are a Problem for Git
Git stores every committed version of every file. Text files often compress well and can be compared as lines. Binary files, such as Photoshop documents, videos, datasets, and game assets, usually produce poor diffs.
If a large binary file changes often, the repository stores many large versions. Cloning, fetching, and backing up the repository then takes more time and disk space. Deleting the file later does not remove its old versions from Git history.
How Git LFS Works
Git Large File Storage (Git LFS) keeps large file content outside normal Git objects. Git stores a small pointer file instead. The pointer identifies the real content with a SHA-256 hash and records its size. The LFS server stores the content addressed by that hash.
When you check out a file, Git LFS uses filters to replace the pointer in your working tree with the actual content. The commit remains small, while collaborators can still work with the original file.
Installing Git LFS
Install Git LFS using your operating system’s package manager or installer. Then enable it for your user:
git lfs installThis configures Git’s LFS filters and hooks. You normally run it once per user account.
Choosing What to Track
Use git lfs track with a pattern. This records the pattern in .gitattributes:
git lfs track "*.psd"
git add .gitattributes
git add design/logo.psd
git commit -m "Track Photoshop assets with LFS"The pattern applies to matching files in the repository. Commit .gitattributes so every clone uses the same rule.
*.psd filter=lfs diff=lfs merge=lfs -textTrack files that are large, binary, and changed often. Do not track every file automatically. Small text files, source code, and files that need line-based merging usually belong in regular Git.
Exercise
Why must .gitattributes be committed after running git lfs track?
Show answer
It records the LFS filter pattern in the repository, so other clones know which files use LFS.