A brief about Git LFS
Hey there! I’m Srebalaji. You are receiving this email because you have subscribed to level up your game in Git.
Git Large File Storage (LFS) is a git extension that helps you to handle large files in your repo
As we all know Git is a version control tool that tracks changes in all files in the repo
Imagine if you have a large file in your repo, Git has to track every change in that file ever made, and the repo size will increase drastically
To mitigate this one, LFS was built and it’s an open-sourced tool
How it works
LFS handles large files using a simple trick. It won’t download all the large files in your local repo.
Instead, it will download large files whenever required. For example, when you checkout to a commit that has the changes in one of the large files.
To put in the another word, LFS helps us to download a version of the large file whenever required
So whenever the entire file is not required, LFS just replaces the large file with a special pointer. And when you need the original file to see the change or do some changes, LFS will download that file from the server
To use LFS, you need to install the extension locally (which we will cover later) and the remote server should also support LFS.
Github, Gitlab, and Atlassian support LFS. If you are hosting your own Git server, ensure you have support for LFS.
How to use Git LFS
You have to install LFS on your machine.
You can use brew, Linux package, or binary files directly.
Once it’s done to complete the installation, you have to run
git lfs install
This will complete the installation process
You can tell LFS to explicitly track files or folders to handle large files
git lfs track assets/image.png
git lfs track packages/*
Once you have some files or folders to track, .gitattributes
file is created and it has all the tracked files and folders
Then, you can commit all changes which contain gitattributes file and large files.
When you push, large files which are tracked by LFS will be pushed to the server. This is achieved because LFS installs a pre-hook in your repo when you install it.
So the Git repo in the remote will have the pointers to that large files. And large files are uploaded to the server.
To conclude, Git LFS helps you to manage large files effectively without much hassle and with little configuration.
That’s all for today folks
See you next week :) :)