Gangmax Blog

Git Large File Storage

Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.

In my case I want to save a sqlite db file with LFS. Here is the commands I use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 1. Install LFS. From: https://packagecloud.io/github/git-lfs/install
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
# 2. Remove the db file from the existing git repository.
cd .newsbeuter
rm cache.db
git commit -m 'Remove the cache.db for later using lfs support.'
# 3. Initialize the lfs feature.
git lfs install
# 4. Declare to use lfs with the "*.db" files.
git lfs track "*.db"
# 5. Read the file content without modification.
vi .gitattributes
# 6. Add the "cache.db" file again.
mv ../cache.db .
git commit -m 'Use the Github lfs support to store the cache.db file.'
# 7. Push to the remote git repository.
git push origin master

I don’t know why that, after I enable LFS feature, I have to type the username/password THREE times instead of once after running “git push” command.

Added on 2018-01-15.

How to make git lfs work after clone a git repository which uses git lfs.

1
2
3
4
5
6
7
8
9
10
11
# 1. Install git lfs.
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
# 2. Clone the original repo and enable git lfs.
git clone <URL>
cd <dir>
git lfs install
git lfs track "*.db"
rm *.db
# 3. Get the original lfs file.
git checkout -- .

Added on 2018-02-14.

When running the “curl” command on Linux Mint to install “git-lfs” repository, the created source file should be updated as below to avoid error that no package can be used:

/etc/apt/sources.list.d/github_git-lfs.list
1
2
3
4
5
6
7
# From the following lines:
# deb https://packagecloud.io/github/git-lfs/linuxmint/ sylvia main
# deb-src https://packagecloud.io/github/git-lfs/linuxmint/ sylvia main
# to the following line:
deb https://packagecloud.io/github/git-lfs/ubuntu/ xenial main
# The reason of this error is the source does not have pacakge for
# "linuxmint/sylvia", so manually change it to "ubuntu/xenial".

Here is the LFS specification document, in which more details are given.

Comments