Sub topic 13
Alternatives and when not to use LFS
This chapter assumes you can clone, commit, push, and pull with Git. It also assumes you have read the earlier chapters on pointer files, tracking patterns, migration, and LFS servers. Git LFS solves one problem well: large binary files that change occasionally and belong next to the code that uses them. It is not the right answer for every large file. This chapter gives you criteria for deciding when to use it and what to use otherwise.
What LFS costs you
Before comparing alternatives, list what LFS adds to a project.
- Every contributor needs the extension. A clone without Git LFS installed gives people pointer files instead of real content.
- The server must support it. The Git host needs an LFS endpoint, and that endpoint has storage and bandwidth quotas.
- History is still permanent. Once a file is in LFS, old versions stay on the server. Deleting the file from the latest commit does not free space.
- Migration rewrites history. Moving existing files into LFS with
git lfs migrate importchanges commit IDs and needs a coordinated force push. - CI must opt in. Pipelines need explicit configuration, such as
lfs: truein the checkout step. - Two systems can drift apart. Git can hold a pointer whose object is missing on the server, which produces "missing object" errors.
None of these costs is large for a team that needs LFS. They are a reason not to add it by habit.
When LFS is a good fit
LFS works best when all of the following are true.
- The files are binary or otherwise do not diff or merge well, such as
.psd,.fbx,.wav, or compiled test fixtures. - The files change a few times over the project's life, not on every build.
- The files must be versioned in step with the source code. For example, a texture at the commit that references it.
- Your Git host supports LFS and its quota covers your expected volume.
- The whole team can install the extension.
If one of these fails, look at the alternatives below.
Alternatives
Keep the files out of Git entirely
Some large files are not source. Build outputs, installers, and release bundles can be rebuilt or published elsewhere.
- Put build artifacts in an artifact repository or object storage, such as an S3 bucket, and publish them from CI.
- Attach release binaries to the host's release feature instead of committing them.
- Add generated files to
.gitignoreso nobody commits them by accident.
Use this when the file can be reproduced from the source at a given commit. Git then stores only the recipe.
Package managers and registries
If the large file is a dependency, such as a compiled library or a model that many projects share, a package registry is usually better than LFS. The consuming project records a name and version in a manifest, and the tool downloads the file. You get versioning, caching, and checksums without storing the bytes in your repository.
Object storage with a manifest
You can store large files in a bucket and commit a small text file that records where each one lives and its checksum. A script downloads and verifies the files.
#!/usr/bin/env bash
set -euo pipefail
# assets.sha256 contains lines like: <sha256> textures/wall.png
# BASE_URL is the bucket location, for example https://example.com/assets
BASE_URL="${BASE_URL:?set BASE_URL first}"
while read -r sum path; do
if [ ! -f "$path" ] || ! echo "$sum $path" | sha256sum --check --status; then
mkdir -p "$(dirname "$path")"
curl -fsSL "$BASE_URL/$sum" -o "$path"
echo "$sum $path" | sha256sum --check
fi
done < assets.sha256This is close to what LFS does, but you maintain the tooling yourself. It makes sense when you need storage that your Git host's LFS service cannot offer, or when the files are shared by several repositories.
Dedicated data versioning tools
For datasets and machine learning models, tools such as DVC work like LFS in spirit. They keep small metadata files in Git and put the data in remote storage you choose, such as S3 or a shared drive. They also describe pipelines that produce the data. Choose one when your data is large, lives in your own cloud storage, or is produced by multi-step processing that you want to reproduce.
Git submodules or a separate repository
You can put the large assets in their own repository and include it in the main one as a submodule. Developers who only need code can skip the assets repository. The cost is the usual submodule friction: pinned commits, extra update commands, and easy mistakes when contributors forget to initialise them. A separate repository can itself use LFS, so this combines with LFS rather than replacing it.
Partial clone
Git has a built-in feature that limits what a clone downloads. A partial clone asks the server to omit some objects, and Git fetches them later when needed.
git clone --filter=blob:limit=1m https://example.com/team/assets.gitThis skips blobs larger than 1 MB at clone time. It needs a server that supports the filter. It reduces download size but does not shrink the server's history, and it does not offer LFS features such as locking or a separate quota. It is a good option when the problem is clone time on a large history, not storage of binaries.
Shallow clone
git clone --depth 1 downloads only the latest commit. It helps CI jobs that do not need history. It is a performance setting for one clone, not a way to version large files.
Comparing the options
| Option | Files live in | Versioned with code | Extra tooling for users | Best for |
|---|---|---|---|---|
| Plain Git | Git history | Yes | None | Small files, text |
| Git LFS | LFS server | Yes, by pointer | Git LFS extension | Design assets, game assets, fixtures |
| Artifact repository | Registry or bucket | By version number | Download step | Build outputs, releases |
| Package registry | Registry | By manifest | Package manager | Shared binary dependencies |
| Bucket plus manifest | Your storage | By checksum list | Your own script | Custom storage needs |
| DVC or similar | Remote storage you choose | By metadata file | The data tool | Datasets, models, pipelines |
| Submodule | Separate repository | By pinned commit | Submodule commands | Isolating assets from code |
Decision flow
Cases where LFS is the wrong tool
Files that change on every build
If a file is regenerated and committed repeatedly, each version is stored on the LFS server. Storage and bandwidth grow quickly, and the old versions are rarely useful. Publish such files as artifacts instead.
Small binaries
A 20 KB icon does not need LFS. Plain Git compresses and stores it without trouble, and LFS adds pointer files, a server round trip, and a failure mode. A rough rule is to consider LFS once individual files reach a few megabytes or the total of binary history starts to slow clones. Measure before you decide.
Text files that merely look large
Large text files such as JSON, CSV, or SQL dumps compress well in Git and can be diffed. Git stores versions as packed deltas, so many text edits cost little space. LFS stores each version as a full object, so a large text file with small edits can use more space in LFS than in plain Git. Check the real growth with git count-objects -vH before moving it.
Secrets and sensitive data
LFS is not a safer place for credentials or private data. Anyone with access to the repository can fetch the objects. Keep secrets in a secrets manager.
Teams or hosts that cannot support it
If contributors cannot install extra software, or your host has no LFS support or very low quotas, the tool will cause more trouble than it solves. Choose an approach that fits the environment.
Repositories mirrored or forked widely
Forks and mirrors must copy LFS objects separately from Git history. Some hosts count forked LFS storage against quotas, and some mirroring tools skip LFS content. Test a mirror or fork before committing to LFS in a project that is often copied.
Checking before you commit to LFS
Run a quick audit to find the files that are actually large.
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| awk '$1 == "blob" && $3 > 1048576 {printf "%.1f MB %s\n", $3/1048576, $4}' \
| sort -rn \
| head -20The command lists the 20 largest files over 1 MB anywhere in history. If the list is empty or contains only a few files you could delete, you may not need LFS. If it shows many binary assets, use git lfs migrate info to see which patterns account for the most space, then decide what to migrate.
git lfs migrate info --everything --above=1MBLeaving LFS
You can also move files out of LFS. git lfs migrate export rewrites history so that matching files become ordinary Git blobs again, and then you can remove the tracking line from .gitattributes.
git lfs migrate export --include="*.csv" --everything
git push --force-with-lease --allThis rewrites commit IDs, so it needs the same coordination as an import. Check the result with git lfs ls-files, which should no longer list the exported files.
Exercise
Your repository holds a 400 MB compiled installer that CI rebuilds from source on every release, and a 15 MB Photoshop file that designers update a few times a year. Which tool fits each file, and why?
Show answer
Do not commit the installer. It can be rebuilt from source, so publish it as a release asset or in artifact storage and add it to .gitignore. Track the Photoshop file with Git LFS. It is binary, cannot be merged, changes rarely, and must stay in step with the code that uses it.
Exercise
A teammate wants to move a 60 MB CSV file into LFS. The file gets small line edits several times a week. What would you check first, and what could go wrong?
Show answer
Check how much space the file's history takes in plain Git, for example with git count-objects -vH. Git stores text edits as compact deltas and can diff the file. LFS stores every version as a full 60 MB object, so storage and bandwidth use could rise sharply. Keeping the file in plain Git, or moving it to a data versioning tool, may be better.
Exercise
You need only to speed up CI clones of a repository whose history contains many large blobs. You do not want to change history. Name two options that do not involve LFS.
Show answer
Use a shallow clone with git clone --depth 1, and use a partial clone with a filter such as --filter=blob:limit=1m if the server supports it. Both reduce what CI downloads without rewriting history.