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 install

performs several setup steps:

StepExplanation
Install hooksAdds Git Hooks (Git钩子) such as pre-push
Configure GitEnables LFS Filters (LFS过滤器)
Activate LFSAllows Git to replace large files with pointer files (指针文件)

After installation, Git will automatically:

  1. detect large files
  2. store them in LFS storage (LFS存储)
  3. keep only small pointer references in the repository

2. How Git LFS Works (工作原理)#

Normal Git workflow:

file → git repository

Git LFS workflow:

large file → LFS server
pointer file → git repository

Example pointer file:

version https://git-lfs.github.com/spec/v1
oid sha256:xxxx
size 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 install

2) Track large files#

Example:

git lfs track "*.pt"

This tells Git to manage .pt files using LFS.

3) Commit tracking rules#

git add .gitattributes
git commit -m "track model files with LFS"

4) Add large file#

git add model.pt
git commit -m "add model"
git push

The file will be stored in LFS storage (LFS服务器).

4. When You Need git lfs (什么时候需要)#

You should use Git LFS when managing:

File TypeExample
Machine learning models.pt, .pth
Datasets.csv, .parquet
Game assetstextures, audio
Large binariescompiled 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 version

Example output:

git-lfs/3.4.0

Check 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/
Author
Alexander Lee
Published at
2026-03-14
License
CC BY-NC-SA 4.0