Skip to main content
Chapter 46 of 61 · 3 sections · Page 159

Git: Git Large File Storage (LFS)

Track binary assets and heavy files via external pointers using Git LFS and .gitattributes.

Original chapter reference: Chapter 46: Git Large File Storage (LFS). The command options and documentation recipes below are fully transcribed from Git Notes for Professionals.

Section 46.1: Declare certain file types to store externally

A common workflow for using Git LFS is to declare which files are intercepted through a rules-based system, just like .gitignore files.

Much of time, wildcards are used to pick certain file-types to blanket track.

e.g. git lfs track "*.psd"

When a file matching the above pattern is added them committed, when it is then pushed to the remote, it will be uploaded separately, with a pointer replacing the file in the remote repository.

After a file has been tracked with lfs, your .gitattributes file will be updated accordingly. Github recommends committing your local .gitattributes file, rather than working with a global .gitattributes file, to help ensure you don't have any issues when working with different projects.

Section 46.2: Set LFS config for all clones

To set LFS options that apply to all clones, create and commit a file named .lfsconfig at the repository root. This file can specify LFS options the same way as allowed in .git/config.

For example, to exclude a certain file from LFS fetches be default, create and commit .lfsconfig with the following contents:

Source example · PDF page 159
[lfs]
    fetchexclude = ReallyBigFile.wav

Section 46.3: Install LFS

Download and install, either via Homebrew, or from website.

For Brew,

Source example · PDF page 159
brew install git-lfs
git lfs install

Often you will also need to do some setup on the service that hosts your remote to allow it to work with lfs. This will be different for each host, but will likely just be checking a box saying you want to use git lfs.

Buy me a coffee
Daily Practice
0/0