Sneak peak into Git LFS(Large File Storage System)
Tags: git, opensource, github, devhack
Published: 2022-12-24 18:40:46

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eb7rfex9benjlkazjdpo.gif)  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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwrqzd5w7y631wux7c3g.gif)
Yes! it throws the error `Files with larger size should be tracked through LFS`, 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8qgbp84zs32tpz7dbgh.png)


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
```
for other os platforms please refer [this](https://git-lfs.com/)
In my case, I gonna initiate new repo and some dummy files with 200Mb size 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tg8nvl10lk02lb5f1uxc.png)



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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ygu5e6tivsnk8vdhdpcs.png)

> 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"
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ffl5ci1zkct1ejhtpp4.png)




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"
```

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
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ih937l3z6rxg337gor97.png)



> Step -5 : Let's push use the command to push the large file First
```
git lfs push --all origin <branch>
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1be9rzosm4lw84ggesb4.png)

Then  regular push
```
git push origin 
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lecntdgkdad79bboigsi.png)

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 :)