Sub topic 11
Checking out LFS files in CI
This chapter assumes you can clone, commit, and push with Git, and that you have already tracked files with git lfs track and seen pointer files. Here you will learn how to make a CI job receive real LFS content instead of pointers.
Why CI sees pointer files
A CI runner starts from a clean machine. It clones your repository, and the clone contains whatever Git stores in commits. For LFS-tracked files, that is a small pointer file. The real content is downloaded only when the LFS smudge filter runs and can reach the LFS server.
If a runner has no Git LFS installed, or the checkout step skips LFS, your build sees text files like this:
version https://git-lfs.github.com/spec/v1
oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393
size 12345A build that expects an image, dataset, or binary will then fail in confusing ways, such as "not a valid PNG" or a checksum mismatch.
GitHub Actions
In GitHub Actions, the checkout action downloads LFS content only when you ask for it:
steps:
- uses: actions/checkout@v4
with:
lfs: trueGit LFS is preinstalled on GitHub-hosted runners. On self-hosted runners you must install it yourself and run git lfs install for the runner's user.
Other CI systems
Most systems follow the same pattern: make sure the git-lfs binary exists, enable the hooks and filters, and fetch the objects. If your CI offers no LFS option in its checkout step, run the commands yourself:
git lfs install --local
git lfs pullgit lfs install --local sets up the filters for this repository only, which suits shared runners where you should not change the user's global config. git lfs pull fetches the LFS objects for the current checkout and replaces pointer files in the working tree.
Download only what the job needs
Downloading every LFS object slows pipelines and uses your bandwidth quota. A lint job, for example, rarely needs 4 GB of textures. You can skip the automatic download during clone and then fetch a subset:
GIT_LFS_SKIP_SMUDGE=1 git clone https://example.com/team/assets.git
cd assets
git lfs pull --include="textures/"GIT_LFS_SKIP_SMUDGE=1 leaves pointer files in place. --include then downloads only matching paths. Use --exclude to do the reverse.
Authentication and quotas
The LFS server needs credentials, just like the Git remote. In most hosted CI systems, the token that clones the repository also works for LFS on the same host. Problems appear in these cases:
- The job clones from one host but the LFS server is another, and the token covers only one.
- A job uses a read-only token and tries to push LFS objects.
- The account has exhausted its LFS storage or bandwidth quota, so downloads fail with an error about quota or a 403/429 response.
Every CI run that downloads LFS content counts against bandwidth. Frequent pipelines on large files can use a monthly quota quickly. Caching the LFS directory (.git/lfs) between runs, and limiting downloads with --include, reduces that cost.
Verifying in the pipeline
Add a quick check early in the job so failures are clear:
git lfs ls-files
git lfs status
head -c 200 design/logo.psd | grep -q "git-lfs.github.com" && echo "Pointer file, not real content" && exit 1git lfs ls-files lists the files LFS manages. In its output, an asterisk after the object ID means the content is present, and a minus sign means only the pointer is present. The grep line fails the job if a file you need is still a pointer.
| Symptom in CI | Likely cause | Fix |
|---|---|---|
| Files are tiny text files starting with `version https://git-lfs...` | Checkout did not fetch LFS | Set `lfs: true` or run `git lfs pull` |
| `git: 'lfs' is not a git command` | Git LFS is not installed on the runner | Install `git-lfs` in the image or job |
| `Smudge error` or `object does not exist` | Objects were never pushed, or the token cannot read them | Push from a machine with the objects, then check token scope |
| 403 or quota error on download | Storage or bandwidth limit reached | Raise the quota, cache, or use `--include` |
Exercise
A GitHub Actions job uses actions/checkout@v4 with no extra options, and your tests fail because data/model.bin is a 130-byte text file. What is the cause, and what is the smallest change that fixes it?
Show answer
The checkout step did not download LFS content, so the workspace holds the pointer file. Add with: lfs: true to the checkout step. If you only need part of the data, you could instead skip smudge and run git lfs pull --include="data/".
Exercise
You want a CI job to download only the textures/ directory. Which environment variable and command do you use?
Show answer
Set GIT_LFS_SKIP_SMUDGE=1 when cloning so pointer files are left in place, then run git lfs pull --include="textures/".