Cheap git lfs alternative

22 January 2022

How to store large files in git without lfs … if you have no other option

So today I was in need of an alternative to git lfs. LFS has its own limitations, it needs server support and special handling for authentication via HTTPS.

I did not have the time to work around these, and the end result was this hack of a process.

  1. create an orphan tree using git checkout --orphan
  2. store a single file in the tree and commit it
  3. check the file blob id using git ls-tree <commit-id>
  4. create a tag pointing to the file block git tag <tagname> <blob-id>
  5. push the tag upstream using git push origin --tags

To retrieve the file you can then use:

$ git cat-file blob <tagname> > filename

This does NOT address all issues that git-lfs does, but at least the file is a single object and requires zero support on the server side.

The downside is that a git clone is still expensive, but at least you can manually delete those files. I have not checked yet, but maybe a combination of git clone --no-tags or --single-branch can avoid the expensive fetch.