Git LFS for large files - Time & Space Complexity
When working with large files in Git, it is important to understand how operations scale as file size grows.
We want to see how Git LFS handles large files differently from normal Git commands.
Analyze the time complexity of the following Git LFS commands.
git lfs track "*.psd"
git add .gitattributes
git add largefile.psd
git commit -m "Add large PSD file"
git push origin main
This code tracks large files with Git LFS, adds them, commits, and pushes to remote.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Uploading large file data to remote storage.
- How many times: Once per large file during push, but file size affects upload time.
As file size grows, the time to upload the file grows roughly in direct proportion.
| Input Size (MB) | Approx. Operations (Upload Time) |
|---|---|
| 10 | Short upload time |
| 100 | About 10 times longer upload |
| 1000 | About 100 times longer upload |
Pattern observation: Upload time grows linearly with file size.
Time Complexity: O(n)
This means the time to push large files grows directly with the file size.
[X] Wrong: "Git LFS makes pushing large files instant regardless of size."
[OK] Correct: Git LFS stores large files outside Git but still uploads the full file, so bigger files take longer to push.
Understanding how Git LFS handles large files helps you explain efficient version control in real projects.
What if we used Git LFS with many small files instead of one large file? How would the time complexity change?
Practice
Solution
Step 1: Understand Git LFS functionality
Git LFS stores large files outside the main Git history to keep the repository lightweight.Step 2: Compare options with Git LFS purpose
Options A, B, and C describe unrelated features; only To store large files outside the main Git repository history matches Git LFS's main goal.Final Answer:
To store large files outside the main Git repository history -> Option DQuick Check:
Git LFS purpose = store large files externally [OK]
- Thinking Git LFS compresses files inside Git
- Assuming Git LFS merges conflicts automatically
- Believing Git LFS converts files to text
.psd files using Git LFS?Solution
Step 1: Recall Git LFS tracking syntax
The correct command to track files isgit lfs track "pattern".Step 2: Check each option's syntax
Only git lfs track "*.psd" uses the correct command and pattern syntax. Others are invalid commands.Final Answer:
git lfs track "*.psd" -> Option BQuick Check:
Correct Git LFS track syntax = git lfs track [OK]
- Swapping command order like 'git track lfs'
- Using 'git lfs add' instead of 'track'
- Trying to add files directly with 'git add lfs'
git lfs track "*.mp4" and committing, what will happen when you add a new video.mp4 file and push?Solution
Step 1: Understand effect of tracking and committing .gitattributes
Tracking '*.mp4' and committing .gitattributes tells Git to use LFS for .mp4 files.Step 2: Add and push a new .mp4 file
Git LFS stores the file outside Git history and pushes it separately, so Thevideo.mp4file is stored in Git LFS and pushed separately is correct.Final Answer:
Thevideo.mp4file is stored in Git LFS and pushed separately -> Option AQuick Check:
Tracked files use LFS storage on push [OK]
- Assuming large files push normally without LFS
- Thinking Git rejects large files automatically
- Believing tracked files are ignored
git lfs track "*.zip" but forgot to commit .gitattributes. What problem will occur?Solution
Step 1: Understand role of .gitattributes in Git LFS
.gitattributes stores tracking rules and must be committed to share them.Step 2: Effect of not committing .gitattributes
Other clones won't know to track .zip files with LFS, so Git LFS will not track .zip files on other clones is correct.Final Answer:
Git LFS will not track .zip files on other clones -> Option CQuick Check:
Commit .gitattributes to share LFS tracking [OK]
- Assuming local tracking affects other clones
- Thinking Git blocks adding files without .gitattributes
- Believing tracking works without committing
.psd and .mp4 files with Git LFS. Which sequence correctly sets this up and shares it with your team?Solution
Step 1: Track each file type separately
Git LFS requires separate track commands for each pattern, so run both track commands.Step 2: Commit and push .gitattributes to share tracking
Committing and pushing .gitattributes shares tracking rules with the team.Final Answer:
Rungit lfs track "*.psd"andgit lfs track "*.mp4", then commit and push.gitattributes-> Option AQuick Check:
Track each pattern + commit .gitattributes [OK]
- Trying to track multiple patterns in one command incorrectly
- Forgetting to commit .gitattributes
- Running git lfs install after adding files
Ready to prove it?
Pass the test and this pattern moves unknown
