How to deal with big files in your repository

How to deal with big files in your repository#

Some projects have large data file. Storing them directly in the repository is not a good practice. Moreover, collaborators might not need all the data files committed. For such projects, we use Git LFS (Large File Storage). To set it up, follow the instructions below.

  1. Download and install the Git command line extension.

    • Debian

    curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
    sudo apt-get install git-lfs
    
    • Installation on MacOS with Homebrew:

    brew install git-lfs
    
    • Other operational systems: follow instructions here.

  2. Set up Git LFS for your user account by running:

    git lfs install
    
  3. Choose which files to track.

    • Track a specific file file.bigfile:

    git lfs track "file.bigfile"
    
    • Track files with .bigfile extension:

    git lfs track "*.bigfile"
    

    To track files that were not tracked before adding .gitattribute, do:

    git lfs migrate import --everything
    

    This steps will update .gitattributes so run:

    git add .gitattributes
    

    and commit.

Now, every time a .bigfile is added to the repository, it will be tracked as LFS.

Usage instructions

To clone a repository without downloading LFS files

git clone --filter=blob:none <your-repository>

To pull a specific file:

git lfs pull --include="<file>.bigfile"