DEV Community

Cover image for Sneak peak into Git LFS(Large File Storage System)
carrot.py
carrot.py

Posted on • Edited on

Sneak peak into Git LFS(Large File Storage System)

Hi Folks,

Yes! I'm back with an interesting blog Git LFS- An file storage system by git (basically to store large files above 100Mb)

A small back story How I came to know about this!

Recently my colleague asked me Have you ever worked in git Lfs ? I just ignored him like this and get back to my work
Image description Lately, my Manager told us to push changes we were working on for a month(it includes 500Mb of CSV and txt files) when we try to Push it to the remote
git tell us this
Image description
Yes! it throws the error Files with larger size should be tracked through LFS,

Image description

it almost spoiled our holiday eve!!
After spending almost a day, we figured out what is Git LFS and how to push the files!!!!
Here are some Steps to start with Git LFS and some important points so that it won't spoils Your Holiday eve

What is Git LFS?

Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git while storing the file contents on a remote server

OK, Enough is Enough!
Let's Push Files!

Before getting started we need to install git LFS!
if you are a Mac user use

brew install git-lfs
Enter fullscreen mode Exit fullscreen mode

for other os platforms please refer this
In my case, I gonna initiate new repo and some dummy files with 200Mb size

Image description

Now let's add the 200Mb into LFS

I assume you know basic git actions(add, commit,push)

Step-1: This command will set up the Git LFS in your current repo

git lfs install
Enter fullscreen mode Exit fullscreen mode

Image description

Step-2: We need to tell git which type of files or which files needed to be tracked to LFS. The below command will create .gitattributes file contains a list of tracked files

git lfs track "*.csv"
Enter fullscreen mode Exit fullscreen mode

Image description

For example:

if You are working in psd files and need to add all the psd files in LFS means you will give a pattern like "*.psd"
OR
if you need to add all the file under some folder You can give like path/folder_name/** this will add all the files under the path

Step-3: Now add the .gitattributes and commit it as we do before

git add .

git commit -m "initial commit"
Enter fullscreen mode Exit fullscreen mode

This will add all the changed files to the stage and commit those!

Step -4 : Make sure that all Your files are tracked in LFS use the below command to see the list of tracked files

git lfs ls-files
Enter fullscreen mode Exit fullscreen mode

Image description

Step -5 : Let's push use the command to push the large file First

git lfs push --all origin <branch>
Enter fullscreen mode Exit fullscreen mode

Image description

Then regular push

git push origin 
Enter fullscreen mode Exit fullscreen mode

Image description

Tada, it's all done!

Points to remember!

  1. Make sure the file format is correct and not corrupted
  2. Files above 100 MB should be added via Git LFS below that we can add through regular git actions

Thanks, @iamadhee (Lol! he is the colleague I ignored)

Thanks! folks Thanks for reading
Let me know your experience in comment section after using git LFS and the struggles you faced, I will try to post the fix :)

Top comments (0)