cycool29's blog



“Knock, knock … Who’s there? … *very long pause* … Java.”

Subscribe via RSS

Subscribe via Email

11 August 2023

Storing Large Files on GitHub with Git LFS

Read on Medium

Read on Dev.to

5 mins read

by cycool29


Table of Contents


GitHub has become the go-to platform for collaborative software development, allowing developers to work together seamlessly on projects of all sizes. However, when it comes to version control for projects that involve large files, the standard Git repository can fall short due to its limitations. This is where Git LFS (Large File Storage) comes into play. Git LFS is a fantastic solution that enables developers to manage and store large files efficiently within their GitHub repositories, without compromising on performance or slowing down the development process.

Understanding the Challenge

Git, the distributed version control system that powers GitHub, was primarily designed to manage text-based source code files. While it excels at tracking changes in code, it struggles with large binary files like images, videos, audio files, and other non-text assets. Attempting to store large files directly in a Git repository can lead to several issues:

Introduction Git LFS

Git LFS is an open-source extension to Git that addresses these challenges by providing an efficient way to manage large files in a Git repository. Instead of storing the actual content of large files in the repository, Git LFS stores pointers (or metadata) to these files. The actual file content is then stored on a remote server, typically provided by GitHub itself or other supported Git hosting platforms.

Installation

On Linux

Debian and RPM packages are available from packagecloud, see the Linux installation instructions.

On macOS

Homebrew bottles are distributed and can be installed via brew install git-lfs.

On Windows

Git LFS is included in the distribution of Git for Windows. Alternatively, you can install a recent version of Git LFS from the Chocolatey package manager.

From binary

Binary packages are available for Linux, macOS, Windows, and FreeBSD. The binary packages include a script which will:

$ ./install.sh

Note that Debian and RPM packages are built for multiple Linux distributions and versions for both amd64 and i386. For arm64, only Debian packages are built and only for recent versions due to the cost of building in emulation.

From source

Set-up Git LFS

After installation, cd into your repository and configure your repository to use Git LFS by running:

git lfs install

Selecting Large Files

Determine which files in your cloned local repository need to be tracked using Git LFS. Git LFS can be used when you want to version large files, usually, valuable output data, which is larger than the Github limit (100Mb). These files can be plain text or binaries.

  1. Track Files: To start tracking large files, use the command:
    git lfs track "<file_pattern>"
    

    This command tells Git LFS to manage files matching the specified pattern.

  2. Commit and Push: After tracking the necessary files, commit and push your changes to the repository.
    git commit
    git add .
    git push
    

    That’s all! Git LFS will handle the rest, replacing the large files with pointers.

How it Works?

Git LFS operates on a simple yet ingenious principle: it offloads the storage and management of large files from the primary Git repository.


Git LFS is a game-changer for teams working with large files in Git repositories. By separating file pointers from the actual content, Git LFS optimizes storage, enhances performance, and streamlines collaboration. Whether you’re building a game with high-resolution assets, working on video production, or dealing with any project involving large binary files, Git LFS can help you maintain a lean repository without sacrificing version control capabilities. Embrace the power of Git LFS to unlock the full potential of version control for projects of all sizes.

Thanks for reading! 😎

tags: git-lfs - github - large-file - git


Share this article:

Subscribe to our newsletter

Get the highlights in your inbox when there is a new post.

Email Address:

First Name:

Last Name: