git-annex/doc/tips/storing_data_in_git-lfs.mdwn
Joey Hess 5877de5e80
git-lfs: remember urls, and autoenable remotes using known urls
* git-lfs: The url provided to initremote/enableremote will now be
  stored in the git-annex branch, allowing enableremote to be used without
  an url. initremote --sameas can be used to add additional urls.
* git-lfs: When there's a git remote with an url that's known to be
  used for git-lfs, automatically enable the special remote.
2019-11-18 16:09:09 -04:00

69 lines
2.5 KiB
Markdown

git-annex can store data in [git-lfs](https://git-lfs.github.com/)
repositories, using the [[git-lfs special remote|special_remotes/git-lfs]].
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.