Things I forget: install git lfs and initialize in repo

2018/11/04

git lfs is great for including (fairly) large files in git repositories. Since the entire history of files is saved, it prevents large files from blowing up the repo. I’m not sure why it isn’t installed by default with git. Anyway, I always forget how to use it.

Installing git lfs

Each computer accessing a repo with lfs enabled needs to have it installed, otherwise expected files may not appear and the user could (potentially) screw the repo up by deleting the wrong things. More instructions here, but for OS X I just run:

brew install git-lfs
git lfs install

Note that this only needs to be run once per computer, not per repo.

Enabling git lfs on a repo and adding files to it

For each repo, I need to tell git lfs which files or kinds of files to track. Suppose I want to use lfs for any csv files:

git lfs track '*.csv' '*.fst' '*.Rds' '*.gz' "*.zip"
git add .gitattributes '*.csv' '*.fst' '*.Rds' '*.gz' "*.zip"

First line tells lfs which patterns to track, second adds .gitattributes and all of the relevant files (if necessary) to the commit.

Checking in on git lfs

git lfs ls-files: Show a list of tracked files

Sources: