0
0
Gitdevops~10 mins

Git LFS for large files - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Git LFS for large files
Start: Large file in project
Track file with Git LFS
Add file to Git index
Commit changes
Push to remote repository
Large file stored in LFS server
Pointer file stored in Git repo
This flow shows how Git LFS tracks large files by replacing them with small pointer files in Git, while storing the actual large files on a separate server.
Execution Sample
Git
git lfs track "*.psd"
git add .gitattributes
git add bigfile.psd
git commit -m "Add large PSD file"
git push origin main
This sequence tracks PSD files with Git LFS, adds the tracking config, stages the large file, commits, and pushes to remote.
Process Table
StepCommandActionResult
1git lfs track "*.psd"Add pattern to .gitattributesFiles matching *.psd tracked by LFS
2git add .gitattributesStage .gitattributes file.gitattributes ready to commit
3git add bigfile.psdStage large PSD filePointer file staged instead of full file
4git commit -m "Add large PSD file"Commit changesCommit includes pointer and .gitattributes
5git push origin mainPush commit and LFS objectsPointer pushed to Git repo; large file pushed to LFS server
6Execution ends: large file stored separately, Git repo has pointer
💡 Push completes with large file stored on LFS server and pointer in Git repository
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5
.gitattributesemptycontains '*.psd filter=lfs diff=lfs merge=lfs -text'stagedstagedcommittedcommitted
bigfile.psduntrackeduntrackeduntrackedstaged as pointercommitted as pointerpushed to LFS server
Git commitnonenonenonenonecreated with pointerpushed
LFS serveremptyemptyemptyemptyemptylarge file stored
Key Moments - 3 Insights
Why does 'git add bigfile.psd' stage a pointer file instead of the full file?
Because Git LFS replaces the large file with a small pointer file during staging, as shown in execution_table step 3.
What happens to the large file when we push to the remote repository?
The large file is uploaded to the LFS server separately, while Git stores only the pointer, as seen in execution_table step 5.
Why do we need to add and commit the .gitattributes file?
Because .gitattributes tells Git which files to track with LFS, so it must be committed before adding large files (execution_table steps 1 and 2).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is staged when running 'git add bigfile.psd'?
ANothing is staged
BThe full large file content
CA pointer file representing the large file
DOnly .gitattributes file
💡 Hint
See execution_table step 3 where staging replaces the large file with a pointer
At which step is the large file actually uploaded to the LFS server?
AStep 2
BStep 5
CStep 3
DStep 4
💡 Hint
Check execution_table step 5 where push uploads LFS objects
If we forget to commit .gitattributes before adding large files, what happens?
ALarge files are added as normal files to Git
BLarge files are tracked by LFS anyway
CGit throws an error
DPointer files are created but not committed
💡 Hint
Refer to variable_tracker showing .gitattributes must be committed first to enable LFS tracking
Concept Snapshot
Git LFS tracks large files by replacing them with small pointer files in Git.
Use 'git lfs track "pattern"' to specify files.
Add and commit .gitattributes to enable tracking.
Add large files normally; Git stores pointers.
Push uploads pointers to Git and large files to LFS server.
This keeps Git repos fast and small.
Full Transcript
Git LFS helps manage large files by storing them outside the main Git repository. First, you tell Git LFS which files to track using 'git lfs track' which updates the .gitattributes file. Then you add and commit this file so Git knows to use LFS for those files. When you add a large file matching the pattern, Git LFS stages a small pointer file instead of the full file. Committing saves this pointer in Git. When you push, Git sends the pointer to the Git server and uploads the actual large file to the LFS server. This way, your Git repository stays small and fast, while large files are stored efficiently. The execution table shows each step from tracking, adding, committing, to pushing, and the variable tracker shows how files and pointers change state. Key moments clarify why pointers are staged and how the large files are uploaded separately. The quiz tests understanding of these steps.