Git Large File Storage

Required for 100MB+ files on Github

Git Large File Storage

posted in dev-setup on  •   • 

Needed to get around installing git lfs because I’m adding large media files to Obsidian which I’m syncing with a private github repository.

git-lfs/git-lfs : Git extension for versioning large files

It stores your large files on a separate server and works seamlessly with your normal git workflow.

Install

choco install git-lfs -y
git lfs install

Usage

git lfs track "*.mp4"

This will create/update your .gitattributes:

*.mp4 filter=lfs diff=lfs merge=lfs -text

Note the quotes around “*.mp4”, without them your shell will expand and add individual file entries to .gitattributes!

It will also add git hooks for pre-push etc:

#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; }
git lfs pre-push "$@"

You only need to do a git lfs install once. LFS will add the hooks for you when cloning a repository with LFS content.

Performance

If you’re going to clone or pull something with a lot of big lfs files, you can speed up the process by batch downloading the files.

git lfs clone

For a pull you can use this alias to pull without lfs files and then download them separately.

git config --global alias.plfs "!git -c filter.lfs.smudge= -c filter.lfs.required=false pull && git lfs pull"

What!?

  • -c: overrides configuration for this command only
    • Example: git -c user.email="me@company.com" commit -m "Fix bug"
  • filter.lfs.smudge=: the default value is git-lfs smudge -- %f which converts the LFS pointer stored in git with the actual file from the LFS server. We’re setting this to nothing so that it doesn’t do so
  • filter.lfs.required=false: mark lfs files as optional

Configuration

See all lfs related settings, with any of:

git config --list | ? { $_ -like "filter.lfs*" }
git config --list | grep filter.lfs
git config --get-regexp 'filter\.lfs'

Github

  • Github currently doesn’t allow files >2GB.
  • A remote LFS object can only be deleted by deleting the whole repository.
  • An error starting from 100MB and a warning from 50MB.
remote: warning: See https://gh.io/lfs for more information.
remote: warning: File x.mp4 is 57.88 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.

Other interesting reads
Tags: tutorial windows