Git Large File Storage Tutorial

Introduction

Git was originally designed for small file storage. However, in some scenarios, uploading some large files is inevitable. Git Large File Storage (Git-LFS) was invented to make large file storage on Git fast and reliable. When I first use Git-LFS, I found it confusing. Because I don’t use it frequently, I forgot how to use it from time to time. So in this blog post, I will document the basic protocols of using Git-LFS. For more comprehensive usages, please go to the reference section.

Installation

The installation is extremely simple on Linux. Run the following command and you should be good to go.

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

Upload Files

To upload large files to Git server, in the Git repository root directory, run the following commands.

1
2
3
4
5
6
7
8
9
10
11
# Git-LFS initialization
$ git lfs install
# Add the large file pattern to Git-LFS
# It could also be a single filename
$ git lfs track "*.so"
# This step is necessary
$ git add .gitattributes
# Do everything normally as you do in ordinary Git
$ git add .
$ git commit -m "Update files"
$ git push origin master

Download Files

To download the Git repository containing large files, please make sure that Git-LFS was installed beforehand. Otherwise, the repository you cloned will only contain the shortcuts of the large files. Installing of Git-LFS after the repository was cloned will not help. git pull and git fetch will not automatically replace the shortcuts to large files for you. If you have already cloned the repository, just delete the repository, make sure Git-LFS is correctly installed, and clone again. In this way, the large files will be cloned correctly.

References

Author

Lei Mao

Posted on

07-22-2019

Updated on

07-22-2019

Licensed under


Comments