ποΈ Git LFS β Large File Support for Versioning Big Assets in Git
π§² Introduction β Why Use Git LFS?
Standard Git is designed for tracking source code, not large binary files like images, videos, audio, datasets, or executables. If you try to version such files, your repo will grow quickly, become slow, and inefficient.
This is where Git LFS (Large File Storage) comes in.
Git LFS replaces large files with text pointers in your Git history, and stores the actual content in external storage, dramatically improving performance and scalability for large assets.
π― In this guide, youβll learn:
- What Git LFS is and how it works
- How to install and set it up
- How to track, commit, and fetch large files
- Real-world use cases and best practices
π What Is Git LFS?
Git LFS (Large File Storage) is an extension for Git that replaces large files such as media, binaries, and datasets with small pointer files in your Git repository. The actual files are stored in a separate location (like GitHubβs LFS server).
When you clone or pull a repo with Git LFS:
- Git retrieves the lightweight pointer file
- Git LFS downloads the actual large content in the background
π§° How Git LFS Works β Behind the Scenes
- You install Git LFS on your system.
- You tell Git LFS which file types to track (e.g.,
.psd
,.mp4
,.zip
). - When you commit:
- A small text pointer is stored in your Git repo.
- The large file is uploaded to a remote LFS server.
- When you or your team pulls the repo, Git LFS downloads the actual file content automatically.
βοΈ Install Git LFS
π§ For macOS:
brew install git-lfs
π§ For Ubuntu/Debian:
sudo apt install git-lfs
π§ For Windows:
Download from https://git-lfs.github.com/
Then initialize:
git lfs install
π οΈ How to Use Git LFS β Step-by-Step
β Step 1: Install and initialize
git lfs install
β Step 2: Track file types or specific files
git lfs track "*.mp4"
git lfs track "*.zip"
This creates or updates a .gitattributes
file like:
*.mp4 filter=lfs diff=lfs merge=lfs -text
β Step 3: Add and commit as usual
git add .gitattributes
git add large-video.mp4
git commit -m "Add large video using Git LFS"
β Step 4: Push to remote
git push origin main
Git LFS will upload the large files to the LFS server and pointers to Git.
π§ͺ Real-World Example β Add a Dataset
Task: Add data.csv
(200MB) to Git using LFS
git lfs track "data.csv"
git add .gitattributes
git add data.csv
git commit -m "Add dataset with Git LFS"
git push origin main
π Result:
data.csv
content is stored in LFS- A lightweight pointer file is versioned in Git
π Cloning a Repository with LFS Files
git clone https://github.com/user/project.git
Git LFS will automatically download tracked files. If not:
git lfs pull
π Useful Git LFS Commands
Command | Description |
---|---|
git lfs install | Set up Git LFS for your system/repo |
git lfs track "*.ext" | Track file types using LFS |
git lfs untrack "*.ext" | Stop tracking a file pattern |
git lfs status | Show LFS-tracked files and changes |
git lfs ls-files | List files currently tracked by LFS |
git lfs pull | Download LFS files after cloning |
git lfs push | Manually push LFS files if needed |
π§ Git LFS Use Cases
- Storing high-resolution images (e.g.,
.png
,.jpg
,.psd
) - Tracking video/audio files in game or media projects
- Versioning large datasets in ML/AI workflows
- Managing compiled binaries and archives (e.g.,
.zip
,.exe
)
β οΈ Limitations and Quotas
Platform | Free Storage | Free Bandwidth | Notes |
---|---|---|---|
GitHub LFS | 1 GB | 1 GB/month | Additional usage is billable |
GitLab | Similar, varies by plan | May differ | |
Bitbucket | Supports LFS via add-on | Pricing varies |
Important: LFS bandwidth is separate from regular Git usage. Watch your quota if storing large assets!
β Best Practices for Git LFS
- Track only necessary large files (avoid overusing LFS)
- Always commit
.gitattributes
so teammates track the same files - Use
.gitignore
to skip temporary or generated large files - Monitor LFS quotas and bandwidth, especially on GitHub
π Summary β Git LFS
Git LFS is an essential tool for developers working with non-code assets. It keeps your repo size manageable while still allowing version control of large files like videos, datasets, or binaries.
π Key Takeaways:
- Git LFS stores large files outside Git history
- Use
git lfs track
to define which files to manage - LFS improves speed, collaboration, and Git performance
βοΈ Real-World Relevance: Whether you’re building games, ML models, or media platforms, Git LFS is the cleanest way to version large project files without bloating your repo.
β Git LFS β Frequently Asked Questions (FAQs)
β Is Git LFS free to use?
β
Yes, but hosting providers (like GitHub) offer limited free storage/bandwidth. Exceeding it may require a paid plan.
β Where are LFS files stored?
β
On the LFS server of your hosting provider (e.g., GitHub LFS storage). Only a small pointer is kept in the Git repo.
β Can I untrack a file from Git LFS?
β
Yes:
git lfs untrack "file.ext"
git add .gitattributes
git commit -m "Untrack file from LFS"
β What happens if a teammate doesnβt have Git LFS?
β Theyβll only get pointer text files, not actual content. Make sure all collaborators run git lfs install
.
β How do I migrate existing large files into Git LFS?
β
Use the git-lfs-migrate tool to convert files in history to LFS-tracked objects.
Share Now :