435 words
2 minutes
Git LFS (Large File Storage)

I. git lfs install (Git LFS 初始化命令)
Git LFS (Large File Storage,大文件存储) is an extension of Git (版本控制系统) used to manage large files such as datasets, models, or binaries. The command
git lfs install initializes Git LFS on your machine by configuring Git hooks and global settings. In simple words, it prepares Git so that large files will automatically be handled by the LFS system instead of normal Git storage. 1. What git lfs install Does (命令作用)
Running
git lfs installperforms several setup steps:
| Step | Explanation |
|---|---|
| Install hooks | Adds Git Hooks (Git钩子) such as pre-push |
| Configure Git | Enables LFS Filters (LFS过滤器) |
| Activate LFS | Allows Git to replace large files with pointer files (指针文件) |
After installation, Git will automatically:
- detect large files
- store them in LFS storage (LFS存储)
- keep only small pointer references in the repository
2. How Git LFS Works (工作原理)
Normal Git workflow:
file → git repositoryGit LFS workflow:
large file → LFS serverpointer file → git repositoryExample pointer file:
version https://git-lfs.github.com/spec/v1oid sha256:xxxxsize 104857600 Note: A pointer file (指针文件) is a small text file that references the real large file stored in the LFS server.
3. Typical Usage Workflow (常见使用流程)
1) Install Git LFS
git lfs install2) Track large files
Example:
git lfs track "*.pt"This tells Git to manage .pt files using LFS.
3) Commit tracking rules
git add .gitattributesgit commit -m "track model files with LFS"4) Add large file
git add model.ptgit commit -m "add model"git pushThe file will be stored in LFS storage (LFS服务器).
4. When You Need git lfs (什么时候需要)
You should use Git LFS when managing:
| File Type | Example |
|---|---|
| Machine learning models | .pt, .pth |
| Datasets | .csv, .parquet |
| Game assets | textures, audio |
| Large binaries | compiled files |
Warning: Normal Git performs poorly with very large files because the entire file history is stored inside the repository.
5. Verify Installation (验证安装)
Check whether Git LFS is installed:
git lfs versionExample output:
git-lfs/3.4.0Check tracked files:
git lfs ls-files💡 One-line Takeaway
git lfs install initializes Git LFS (Git大文件存储) by configuring Git hooks and filters so that large files are stored in LFS storage instead of the Git repository. Git LFS (Large File Storage)
https://lxy-alexander.github.io/blog/posts/tools/git-lfs-large-file-storage/