Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to install and use Git LFS

📅 2016-Oct-06 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ git, lfs ⬩ 📚 Archive

Git repositories and its hosts like Github have limits on the file size of what can be stored there. While the file size is not really an issue for text files, it becomes a problem if you are trying to use Git to store large binary files. This is usually the case for executable files or libraries, video game assets or deep learning models. Large File Storage (LFS) is an extension to Git that can help you to handle large files. For the rest of this post, we need to assume that your Git server or host (like Github) supports LFS.

$ sudo apt install git-lfs

In older versions of Ubuntu, you had to install from the LFS repository like this:

$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
$ sudo apt install git-lfs
$ git clone https://github.com/joe/foobar

However, note that this will download all the large files in their full size. For a large repository, this will take a long time and you need to make sure you have the space to hold the entire repository of files.

Set an environment variable to skip smudge filter and then clone:

$ GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/joe/foobar

An alternative is to use a git config that does the same:

$ git config --global filter.lfs.smudge "git-lfs smudge --skip"
$ git clone https://github.com/joe/foobar
$ git lfs fetch
$ git lfs checkout foobar.bin
$ git lfs fetch --include foobar.bin
$ git lfs checkout foobar.bin

Alternatively:

$ git lfs pull --include foobar.bin
$ git lfs pointer --file foobar.bin > foobar.bin.pf
$ rm foobar.bin
$ mv foobar.bin.pf foobar.bin
$ git add foobar.bin

To view which large files are modified or not added to the repository:

$ git lfs status

Tried with: Git 2.17.1 and Ubuntu 18.04