Sync folders with git-annex, manually and with v6 repositories

Git annex is a powerful tool to keep track of files of any dimension on multiple locations using git repositories.

I describe a simple use case on Linux: keep two folders in sync without caring for previous versions of files, or their backups (which means that deleting a file on one folder will lead, after syncing, to the file being deleted on the other folder also).
This can be done setting the repositories in direct mode, but the new V6 repositories instead use the concept of locked and unlocked files. We want to use unlocked files.

Note: inexperienced users should be using git annex assistant instead of following this procedure.

Installation

At the moment, V6 is not available in many distro packages, so get the precompiled annex at https://downloads.kitenet.net/git-annex/linux/current/

After unpacking archive to a folder git-annex.linux, I choose to manually enable annex, because I have another version of git installed.
$ cd git-annex.linux
$ PATH=$PWD:$PATH

Spare some minutes to test the system out by issuing a git annex test

Create the first folder

$ cd (path for first folder)
$ git init (folder name)
$ git config user.name "(your name)"
$ git annex init --version=6
$ git config annex.thin true
$ git annex fix

Create the second folder

Note, this can be repeated for any number of additional folders you want to sync
$ cd (path for second folder)
$ git clone (path for first folder)/(folder name)
$ cd (folder name)
$ git config user.name "(your name)"
$ git annex init "(description of folder, usually the location, e.g. USB disk)" --version=6
$ git config annex.thin true
$ git annex fix
$ git remote add (a name for the first folder, e.g. mylaptop) (path for first folder)/(folder name)

Make second folder known to the first one

$ cd (path for first folder)/(folder name)
$ git remote add (a name for the second folder, e.g. usbdisk) (path for first folder)/(folder name)

Note, the “git remote add…” step must be repeated for any number of additional folders you want to sync

Typical workflow

Remember to use the precompiled git-annex
$ cd git-annex.linux
$ PATH=$PWD:$PATH

Get updates from the other folder(s)

Note, the following will delete any file that has been removed in the other folder(s), so this would be a good time to make backups.
$ cd (path for one of the folders)/(folder name)
$ git annex sync --content

Work with the files in the folder

Create, edit, delete, move files as usual

Sync changes

When you are done with working, notify annex about newly added files:
$ git add -A
Note, it is a normal git add, git annex add is for locked files. The -A options adds all files in the current path and subfolders to the repository, so check your current working directory before issuing it.
And finally propagate the changes to the other folder(s)
git annex sync --content

One thought on “Sync folders with git-annex, manually and with v6 repositories”

  1. The local annex installation has the drawback of ssh access problems because annex-shell is in the PATH.
    One way to fix it
    git config remote.(name of remote).annex-shell (full path to the file)

Leave a Reply

Your email address will not be published. Required fields are marked *