Updated on 2023-12-04 GMT+08:00

Using Git LFS

Background

Installing Git LFS

The following table describes the installation on different operating systems.

Table 1 Installing Git LFS

Operating System

Installation Method

Windows

Download and install Git 1.8.5 or a later version. Run the following command in the CLI:

git lfs install

Linux

Download the installation package from PackageCloud for your operating system and CPU architecture.

Decompress the installation package, run the install.sh script to install the software, and then run the following command to check whether the installation is successful:

git lfs version

macOS

Install the Homebrew software package management tool, and run the following commands:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install git-lfs
$ git lfs install

Configuring File Tracking

This section describes how to configure file tracking.

Table 2 Configuring file tracking

Scenarios

Method

Track all .psd files

Run the following command:

git lfs track "*.psd"

Track a file

Run the following command:

git lfs track "logo.png"

View tracked files

Run git lfs track or view the .gitattributes file.

$ git lfs track
Listing tracked patterns
    *.png (.gitattributes)
    *.pptx (.gitattributes)
$ cat .gitattributes
*.png filter=lfs diff=lfs merge=lfs -text
*.pptx filter=lfs diff=lfs merge=lfs -text

Committing Large Files

The .gitattributes file should be pushed to the repository along with the large files. After the push, run git lfs ls-files to view the list of track files.

$ git push origin master
Git LFS:  (2 of 2 files) 12.58 MB / 12.58 MB
Counting objects: 2, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 548 bytes | 0 bytes/s, done.
Total 5 (delta 1), reused 0 (delta 0)
To <URL>
<SHA_ID1>..<SHA_ID2>  master -> master
$ git lfs ls-files
61758d79c4 * <FILE_NAME_1>
a227019fde * <FILE_NAME_2>

Cloning a Remote Repository Containing Git LFS Files

Run git lfs clone to clone a remote repository that contains Git LFS files to the local computer.

$ git lfs clone <URL>
Cloning into '<dirname>'
remote: Counting objects: 16,done.
remote: Compressing objects: 100% (12/12),done.
remote: Total 16 (delta 3), reused 9 (delta 1)
Receiving objects: 100% (16/16),done.
Resolving deltas: 100% (3/3),done.
Checking connectively...done.
Git LFS: (4 of 4 files) 0 B / 100 B

More About Git LFS

For details, see the https://git-lfs.github.com.