How to use Git for large files

Overview

Git is not inherently suitable for storing large files like audio, video, and graphics. Github blocks any push that is greater than 100Mb to ensure performance.

Git Large File Storage is an extension that replaces the large files as text references in Git and stores the actual file on the remote server.

Install git-lfs

We can type the following commands in the terminal to install git-lfs:

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash

apt-get install git-lfs

git lfs install

On Mac, we can replace the first two commands with:

brew install git-lfs
Terminal 1
Terminal
Loading...

Set up the repository

We would need to configure lfs in each Git repository where we want to use git-lfs.

git lfs track "*.psd"

We can also create and edit the .gitattributes file directly. We need to make sure that the .gitattributes file is tracked in Git.

Finally, we simply commit and push.

Note that simply tracking a file will not convert any existing files tracked in Git to lfs. We can use git lfs migrate for doing that.

Example

Let’s add a largeFile.pdf in the GitHub repository

This repository needs to be cloned to the local machine.

Create/copy the file in the cloned repository folder on local.

git init
ls -A
git lfs track "*.pdf"
cat .gitattributes

Try out the above commands.

Terminal 1
Terminal
Loading...

On Github, the file would show up as follows:

widget

The contents of the .gitattributes file can also be seen on Github.

Free Resources