Sub topic 2
Committing and Pushing LFS Files
Assume you know clone, add, commit, push, and pull, and that you understand branches and remotes. Git LFS, or Large File Storage, keeps large binary content outside normal Git objects. Git stores a small pointer file in the commit and uploads the real content to an LFS server.
Committing and pushing LFS files
Install and enable LFS once on your computer. Then track a file pattern. The tracking command updates .gitattributes, which tells Git to use LFS for matching files.
git lfs install
git lfs track "*.psd"
git add .gitattributes design/logo.psd
git commit -m "Add logo source file via Git LFS"
git push origin mainWhen Git stages design/logo.psd, the LFS filter replaces its committed content with a pointer. During a push, Git sends the commit and the LFS client uploads the corresponding binary object.
The working tree still contains the real file after checkout. The pointer is normally visible only inside Git's object database or when LFS content has not been downloaded.
Inspecting what LFS is managing
Use these commands to compare tracked patterns, managed files, and local changes:
git lfs track
git lfs ls-files
git lfs statusgit lfs track reads the patterns in .gitattributes. git lfs ls-files lists files currently tracked by LFS. git lfs status reports LFS files that are staged, modified, or ready to be pushed.
If a file is missing from git lfs ls-files, check both its pattern and whether .gitattributes is committed. A pattern added after a file was committed does not automatically rewrite older history.
Cloning and fetching LFS content
A normal clone downloads LFS content during checkout. To avoid downloading every large object, skip automatic downloads and fetch only a directory:
GIT_LFS_SKIP_SMUDGE=1 git clone https://example.com/team/assets.git
cd assets
git lfs pull --include="textures/"git lfs fetch downloads objects into the local LFS cache without updating files in the working tree. git lfs pull fetches objects and updates the working tree. If a file contains pointer text instead of binary content, run git lfs pull and verify that the remote LFS server and credentials are configured.
Exercise
Which command downloads selected LFS files and places their real content in the working tree?
Show answer
git lfs pull --include="textures/".