ID: I202512181300
Status: idea
Tags: git

Git LFS Cheatsheet

Initial Setup

Install Git LFS (one-time):

git lfs install

This registers Git LFS globally on your machine.

Initialize Git LFS in a repo:

git lfs track "*.pdf"
git lfs track "*.mp4"
git lfs track "*.psd"

Creates .gitattributes file (commit this to the repo).

Track multiple file types at once:

git lfs track "*.{pdf,mp4,psd,zip}"

View what’s being tracked:

git lfs ls-files

Cloning & Pulling

Clone with LFS files (preferred):

git clone <repo-url>
git lfs install
git lfs pull

Clone without LFS files (pointer files only):

git clone <repo-url>

Pull LFS files after cloning:

git lfs pull
git lfs pull --all

Fetch and checkout separately:

git lfs fetch --all
git lfs checkout

Daily Workflow

Push changes (includes LFS files):

git add .
git commit -m "message"
git push

Git automatically handles LFS files.

Pull updates:

git pull
git lfs pull

⚠️ CRITICAL: Multi-Device Setup

You MUST do this on EVERY device using the repo:

  1. Install Git LFS:
git lfs install
  1. Clone the repo:
git clone <repo-url>
  1. Pull LFS files:
git lfs pull

If you forget on a device, you’ll only see pointer files (the version https://git-lfs.github.com/spec/v1 stubs) instead of actual files.


Troubleshooting

Check if LFS is installed:

git lfs version

See pointer files instead of actual files:

git lfs install
git lfs pull
git lfs checkout

Check LFS storage quota/usage:

git lfs logs last

Remove a file from LFS tracking:

git lfs untrack "*.pdf"
git add .gitattributes
git commit -m "Stop tracking PDFs with LFS"

Migrate existing files to LFS:

git lfs migrate import --include="*.pdf"

Key Points

  • .gitattributes must be committed – share it with all team members
  • All collaborators need git lfs install – or they get pointer files
  • LFS requires remote storage – GitHub, GitLab, Bitbucket, or self-hosted
  • Large files should be tracked – PDFs, videos, images, binaries (>100MB)
  • Small text files should NOT be in LFS – defeats the purpose

References

My pdfs didn’t load and showed this when i opened them:

oid sha256:2cf592be0098338078766687199555e24683660dbdeda00e6cd89a8639707fba  
size 49133