Skip to content

Latest commit

 

History

History
169 lines (108 loc) · 4.68 KB

git_lfs_setup.md

File metadata and controls

169 lines (108 loc) · 4.68 KB

Git LFS Setup Guide

What is Git LFS?

Git Large File Storage (LFS) is an extension to Git that allows you to version control large files efficiently. Instead of storing large files directly in your Git repository, LFS stores only a small pointer file in the repo while the actual file contents are stored on a separate LFS server.

Why Use LFS?

  • Prevents repository bloat: Large files don't inflate your .git folder size
  • Faster cloning: Initial clones download pointers, not full file contents
  • Version control for large data: Track changes to datasets, figures, and other large files
  • Automatic handling: Once configured, LFS works transparently

Installation

  1. Git for Windows installer

  2. Verify installation

    git lfs version

    You should see output like: git-lfs/3.x.x

One-Time Setup (Per User)

After installing Git LFS, run this command once on your machine:

git lfs install

This sets up the necessary Git hooks to make LFS work automatically.

Repository Setup

For This Template Repository

This repository is already configured for Git LFS via the .gitattributes file.

The following directory is tracked by LFS:

  • 01_data/03_large_files_LFS/** (all files in this folder)

Copying this template into an existing repo? Make sure .gitattributes comes across too. A repo created on GitHub may already have its own default .gitattributes (containing only * text=auto), and that file has no LFS rule. Without the LFS rule, files in the large files folder are committed as regular Git files, and GitHub rejects any file over 100 MB on push.

To confirm LFS will pick up a file before committing:

git check-attr filter -- "01_data/03_large_files_LFS/my_file.csv"
# Expected: filter: lfs   (if "unspecified", the LFS rule is missing)

If Cloning This Repository

  1. Ensure Git LFS is installed (see Installation section above)

If Adding LFS to a New Repository

If you're using this as a template and need to set up a new repo:

  1. Initialize Git (if not already initialized)

    git init
  2. Ensure .gitattributes exists

    • This template includes it already
    • It specifies which files should use LFS
  3. Add and commit your files normally

    git add .
    git commit -m "Initial commit with LFS tracking"
  4. Add remote and push

    git remote add origin <repository-url>
    git push -u origin main

How to Use

Adding Large Files

Simply add files to the 01_data/03_large_files_LFS/ directory and commit normally:

Git LFS handles everything automatically - no special commands needed!

Viewing LFS File History

# See which commits modified LFS files
git log --follow -- "01_data/03_large_files_LFS/my_file.csv"

Important Notes

File Size Limits

  • GitHub: 2 GB per file, 1 GB free storage per account If you exceed limits, you may need to purchase additional LFS storage or use alternative solutions.

What NOT to Track with LFS

  • Small files (< 1 MB): Regular Git handles these efficiently
  • Files that change frequently: LFS stores every version, so rapidly changing files accumulate storage
  • Temporary files: These should be in .gitignore instead

What TO Track with LFS

  • Large datasets (.csv, .rds, .parquet files)

Troubleshooting

"This repository is over its data quota"

Your LFS storage limit has been exceeded. Options:

  1. Purchase additional storage from your Git provider
  2. Remove large files from history using git lfs prune
  3. Use external storage (cloud storage) and reference via URLs

"Git LFS is not installed"

Run the installation steps above, then:

git lfs install
git lfs pull

Files not downloading during clone

# Manually fetch LFS files
git lfs pull

Checking if a file is in LFS

# Check if file is an LFS pointer
git lfs ls-files | grep "filename"

# Or examine the file directly
cat "01_data/03_large_files_LFS/myfile.csv" | head -5

If it shows version https://git-lfs.github.com/spec/v1, it's an LFS pointer.

Additional Resources

Summary

Once Git LFS is installed and configured (one-time setup), it works quietly:

  1. Add files to 01_data/03_large_files_LFS/
  2. Commit and push normally
  3. Git automatically handles LFS routing
  4. Collaborators automatically get large files when they clone/pull