### Lei Mao

Machine Learning, Artificial Intelligence. On the Move.

# Git Large File Storage Tutorial

### Introduction

Git was original designed for small file storages. 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.

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


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

# 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


To download 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.