Skip to content

Git LFS tutorial

Git LFS is a Git extension developed by Github to implement Git’s support for large files.

Purpose

In the process of program development, binary files occupy a large part of the space. Files such as png and bin are binary, and the size is also very large.
But git’s diff/patch is based on text files. For binary files, git needs to store the changes of each commit.
Every time the binary file is modified and changed, additional submissions will be generated. As a result, the volume of the online warehouse will also grow rapidly.

LFS (Large File Storage) is a tool created to solve this problem.
It saves the large files you marked to another repository, while keeping only lightweight pointers to them in the main repository.
Then when you check out the version, update the corresponding large file according to the change of the pointer. Instead of saving all versions of the large file locally.

Install

Note: Git version not lower than 1.8.5 is required to install Git LFS

Linux

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

Mac

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

Windows

  1. Download and install windows installer
  2. Run windows installer
  3. Execute git lfs install on the command line

Usage

  1. Execute git lfs install to enable the lfs function
  2. Use the git lfs track command to track large files. For example, git lfs track "*.png" tracks all files with a suffix of png
  3. Use git lfs track to view the existing file tracking mode
  4. Committing code requires submitting the gitattributes file to the warehouse. It keeps track of the file. You can directly modify this file later to specify the files that LFS needs to track
  5. Run git lfs ls-files after submitting to display the list of currently tracked files
  6. After the code is pushed to the remote warehouse, the files tracked by LFS will be displayed in the form of “Git LFS”
  7. When cloning, you can use ‘git clone’ or git lfs clone
Leave a Reply