387 words · 2 min

Git Annex

First a review of git

There are three places files are in git:
    * working directory
    * staging
    * repository

* Create a repo:  `git init`
* Add a file:
    * echo "one" >> readme.md
    * `git add readme.md`
    * `git commit`
    * echo "two" >> readme.md
    * `git commit -am "added two"` to commit in one step
    * echo "three" >> readme.md
    * touch docs
    * `git commit -p "added three and docs"` to stage readme and docs interactively

* create a branch:
    * `git checkout -b capitalizestuff`
    * sed s/one/ONE/g > readme.md
    * `git commit -am "cap 1"`
    * sed s/two/TWO/g > readme.md
    * `git commit -am "cap 2"`
    * sed s/three/THREE/g > readme.md
    * `git commit -am "cap 3"`
* combine commits
    * `git rebase -i HEAD~3`
    * use squash instead of pick for the bottom 2
    * write a new commit message that makes a nice gift to your future reader

* merge a branch:
    * `git checkout master`
    * `git merge capitalizestuff`

Problems with git and large files

Git saves a copy of every version of a file which has a reference, e.g. a
tag or branch.  If you have large binary files, e.g. artwork, database
schema  (large ~ 50mb) everytime you branch, these large files will make
your repo large.

There are two solutions.  (three if you just ignore it)
* git lfs
* git annex

Git Annex

This provides a way to track unversion files, like having an attic where
you put all the things you don't want to pay attention to.  /"I'm not a
hoarder, I just never throw anything away."/

Set up a directory to be an annex repository (it has all the files)
Set up another dir on a remote (accessible via ssh) or usb drive to also be an annex
set up each with remotes pointing to the other: `git annex remote add <label> <destination>`

Looking at the files on the remote, it's just links.

`git annex add <my file>`
`git annex get <my file>`
`git annex move <my file> <remote>`
`git annex drop <my file>`

You can also use special remotes, e.g  google drive, not just normal filesystems:
https://github.com/DanielDent/git-annex-remote-rclone
    *I recommend installing with pipx*   https://pipxproject.github.io/pipx/

A use for git annex is to store pdf's, or mp3's and pull them down only when you need them.  Have a backup for your cloud drive, but only carry around the stuff that you need!

posts · about · github · home