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.
git-lfsWe 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
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.
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 initls -Agit lfs track "*.pdf"cat .gitattributes
Try out the above commands.
On Github, the file would show up as follows:
The contents of the .gitattributes file can also be seen on Github.