git-annex/ tips/ storing data in git-lfs

git-annex can store data in git-lfs repositories, using the git-lfs special remote.

You do not need the git-lfs program installed to use it, just a recent enough version of git-annex.

## getting started

Here's how to initialize a git-lfs special remote on Github.

    git annex initremote lfs type=git-lfs encryption=none url=https://github.com/yourname/yourrepo

In this example, the remote will not be encrypted, so anyone who can access it can see its contents. It is possible to encrypt everything stored in a git-lfs remote, see fully encrypted git repositories with gcrypt.

Once the git-lfs remote is set up, git-annex can store and retrieve content in the usual ways:

    git annex copy * --to lfs
    git annex get --from lfs

But, git-annex cannot delete anything from a git-lfs special remote, because the protocol does not support deletion.

A git-lfs special remote also functions as a regular git remote. You can use things like `git push` and `git pull` with it.

## enabling existing git-lfs special remotes

There are two different ways to enable a git-lfs special remote in another clone of the repository.

Of course, you can use `git annex enableremote` to enable a git-lfs special remote, the same as you would enable any other special remote. Eg, for the "lfs" remote initialized above:

    git annex enableremote lfs

But perhaps more simply, if git-annex sees a git remote that matches the url that was provided to initremote earlier, it will automatically enable that git remote as a git-lfs special remote.

So you can just git clone from the url, and the "origin" remote will be automatically used as a git-lfs special remote.

    git clone https://github.com/yourname/yourrepo
    cd yourrepo
    git-annex get --from origin

Nice and simple, and much the same as git-annex handles its regular remotes.

(Note that git-annex versions 7.20191115 and older didn't remember the url privided to initremote, so you'll need to pass the url= parameter to enableremote in that case. Newer versions of git-annex will then remember the url.)

## multiple urls

Often there are multiple urls that can access the same git repository. You can set up git-lfs remotes for each url. For example, to add a remote accessing the github repository over ssh:

    git annex initremote lfs-http --sameas=lfs url=git@github.com:yourname/yourrepo.git

The `--sameas` parameter tells git-annex that this is the same as the "lfs" repository, so it will understand that anything it stores in one remote can be accessed also with the other remote.

Colocating git-annex and git-lfs

Is it possible to add git-lfs capabilities to a git-annex, without using a special remote?

I guess what I want is, are there any reasonable instructions to graft the hooks so that this is possible:

    $ git init
    $ git-lfs install
    $ git-annex init

And you can alternate between something like below:

    $ git-lfs track "*.exif_thumbnail.*"
    $ git-annex add IMG_0001.jpg
    $ git add IMG_0001.exif_thumbnail.jpg

Obviously this betrays the scenario of extracting thumbnails from the EXIF header and storing them alongside, as another form of metadata. If there's a better workflow to this, that would be appreciated too.

Comment by beryllium — Tue Jul 22 18:11:47 2025
Comments on this page are closed.