Github have made some changes to their policies and no longer allow files larger than 100MB in your repositories, or rather “not as BLOBS”. If I understand it correctly, larger files can have an adverse effect on thier infrastructure as all binary data is stored in a database server. Larger files with content that doesn’t change all that often are easier stored as flat files, and thankfully there’s a (relatively) elegant solution that makes this possible. It’s called Git Large File Storage (Git LFS).
Installing Git LFS
Git LFS is a separate installation on Linux, but it does come bundled in recent Windows installer versions. This extension needs to be initialised once per user per system and can then be used in conjunction with regular git repos. We do this with the install command like so:
git lfs install
Now we can tell Git LFS what types of files we’d like to add. Say I had some video files that need to be stored, and I’d like all MP4 files treated as “large”. Here’s how I’d do that:
git lfs track "*.mp4" git add .gitattributes git commit -m "tracking MP4 files"
We ask LFS to track our file extension, which creates (or adds to an existing) .gitattributes files. We’ll commit that files so our tracking stays in place. Now when we add or change .MP4 files in our repo, LFS will automatically and seamlessly push those to a different infrastructure than the smaller BLOB files – and everyone is happy.
Migrating existing files to LFS
If you had existing large files in your repo that you’d like to migrate over to the LFS servers, you can do this:
git lfs migrate import --include="*.mp4" --everything
This will amend the repo’s history, extract and track all files with this particular extension. To confirm, we can list all LFS tracked files with this command:
git lfs ls-files
Don’t forget to push your changes after this operation runs.
Migrating from LFS to “regular” Git
The reverse is also possible, should you find you no longer want to deal with LFS tracking. The following command will re-integrate all former flat files and turn them into BLOBs again:
git lfs migrate export --include="*.mp4" --everything
I’m not using Github, I have a private server. Do I still need to deal with LFS?
No actually, you can track anything you like and of any size on your own architecture. LFS was introduced specifically to keep the Github servers ticking over nicely. While LFS will work with your own hosted version of Git, you’re under no obligation to use this system.