Year-End Discount: 10% OFF 1-year and 20% OFF 2-year subscriptions!

Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

git

How to use Git for large files

Anjana Shankar

Tired of LeetCode? 😩

Learn the 24 patterns to solve any coding interview question without getting lost in a maze of LeetCode-style practice problems. Practice your skills in a hands-on, setup-free coding environment. 💪

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.

RELATED TAGS

git

Tired of LeetCode? 😩

Learn the 24 patterns to solve any coding interview question without getting lost in a maze of LeetCode-style practice problems. Practice your skills in a hands-on, setup-free coding environment. 💪

Keep Exploring
Related Courses