Nâng CaoGit iconGit

Git LFS là gì? Setup thực tế cho dự án có design files và build artifacts lớn?

Git LFS (Large File Storage): thay vì lưu binary files trực tiếp trong git objects (làm repo phình to), LFS lưu pointer nhỏ trong git, còn actual file lưu trên LFS server riêng.

Setup:

bash
# Install:
brew install git-lfs  # macOS
git lfs install

# Track file patterns:
git lfs track "*.psd"
git lfs track "*.figma"
git lfs track "*.mp4"
git lfs track "*.zip"
git lfs track "dist/**"  # build artifacts

# Commit .gitattributes:
git add .gitattributes
git commit -m "chore: configure Git LFS tracking"

# Push (LFS files upload automatically):
git push origin main

Kiểm tra files đang track:

bash
git lfs ls-files           # files đang trong LFS
git lfs status             # pending uploads
git lfs migrate info       # phân tích files lớn chưa migrate

Migrate history cũ vào LFS:

bash
git lfs migrate import --include="*.psd" --everything
git push --force --all  # cần force push vì history rewrite

Cân nhắc:
- GitHub: 1GB LFS storage miễn phí, sau đó tính phí bandwidth
- CI/CD: cần cấu hình để pull LFS files (GIT_LFS_SKIP_SMUDGE=1 git clone <url> để skip LFS download hoàn toàn)
- Clone: git lfs install --skip-smudge cũng có thể dùng — --no-local KHÔNG liên quan đến LFS

Alternatives: Cloudinary/S3 cho media assets (không cần trong git), artifact registry cho build outputs.

Xem toàn bộ Git cùng filter theo level & chủ đề con.

Mở danh sách Git