Coding/Learn/git/git submodules and lfs
Git & GitHub Complete Course
01.Introduction, Architecture & Configuration
02.Staging Area, atomic Commits & git status
03.Branching, Fast-Forward & 3-Way Merging
04.Stash, Log Visualization & History Inspection
05.Workflows (Git Flow, Trunk-Based) & Semantic Tagging
06.SSH Keys, Remote Repositories & Origin Setup
07.Push, Fetch, Pull & Upstream Tracking Branches
08.Forking, Clones & Open-Source Pull Requests (PRs)
09.GitHub Flow, Branch Protection & GitHub Pages
10.Undoing Changes: git restore & Safe Public git revert
11.Reset: Deep Dive into --soft, --mixed & --hard
12.Commit Amending & Interactive Rebase (git rebase -i)
13.Reflog & Disaster Recovery (Reviving "Lost" Commits)
14.Merge Conflicts Resolution & git rerere
15..gitignore Rules & .gitattributes Cross-Platform Handling
16.Hooks & Automated Quality Assurance (Pre-Commit)
17.Submodules & Large File Storage (Git LFS)
18.GPG Cryptographic Signing & git cherry-pick
19.Advanced Remotes, Garbage Collection (git gc) & Maintenance
20.Capstone: Production Multi-Branch Enterprise Release Pipeline
Course Certificate0%

Complete all lessons to earn

LearnGit Submodules & Large File Storage (Git LFS)
17 / 20 0%
Lesson 17 of 20
6 mins read

Git Submodules & Large File Storage (Git LFS)

PreviousNext Lesson
In Plain English

Git Submodules allow keeping another Git repository as a subdirectory of your main project while tracking specific commit SHAs. Git LFS (Large File Storage) replaces heavy binary assets (audio, videos, 3D models, AI model weights) with lightweight text pointers in Git, storing actual payloads on dedicated object storage.

The Mental Model

"Submodules are like embedding a live satellite office branch within your headquarters; Git LFS is like putting heavy grand pianos in a warehouse and keeping only the claim ticket receipts in your pocket."

Deep Dive: How It Works

Submodule Tracking: Main repo tracks only the 40-character commit SHA of the nested child repository in .gitmodules.

Cloning Submodules: git clone --recurse-submodules automatically initializes and fetches all nested dependencies.

Git LFS Pointers: Replaces multi-MB binary files with ~130-byte text pointer files containing SHA-256 hashes.

Syntax Blueprint

git submodule add https://github.com/org/library.git libs/lib
git lfs install
git lfs track "*.psd"

Add nested submodule repository and track heavy binary patterns with Git LFS.

PointCore Rules to Remember

Point star
Prevents Repo Bloat: Git LFS keeps .git clone sizes lean by downloading only the active revision's binaries.
Point star
Submodule Pinning: Submodules do not automatically track upstream master; they stay locked to exact verified commit hashes.
Point star
.gitmodules File: Version-controlled manifest mapping submodule local paths to remote repository URLs.

Common Beginner Traps & How to Fix Them

Mistake:Cloning a repository with submodules and finding empty subdirectories.

Why it happens: Standard git clone does not fetch submodules automatically.

How to fix: Run git submodule update --init --recursive.

Pro Tip: Run git lfs pull to download LFS binary assets on demand.

Live Interactive Example

Hit Run Code to see it live
Git LFS Configuration
Git 2.45 / CLI
1
2
3
4
5
6
7
8
9
10
Output Console
Click "Run Code" to view the rendered output.
How it works: .gitattributes instructs Git LFS filters to intercept .bin and .onnx model weights.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Configure LFS Model Tracking

  • PointWrite "*.weights filter=lfs diff=lfs merge=lfs -text" to .gitattributes.
  • PointStage and commit with message "chore: track model weights with LFS".
1
2
3
4
5
6
7
8
9
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates