Steps to Implement Git LFS

In order to use Git LFS, first, we need to install it on our system. We can use the following command to do so.

sudo apt-get install git-lfs

Here is the terminal shell pictorial depiction after executing the above commands as follows:  

Now on the repository where we want to use Git-LFS, there we have to set up that.

Step 1: Run the command on the repository. 

git lfs install 

It will initialize the LFS in the repository and will update the Git Hooks.

Step 2: Run the below command as listed:

git lfs track "*.jpg" 

This will tell git lfs to handle the jpg files, in case you want any other file, then you can specify that particular extension.

Step 3: As the configuration that is done on Step 2, is stored in the .gitattributes file, so we will add it for commit using the following command

git add .gitattributes 

Here is the terminal shell pictorial depiction after executing the above commands as follows:  

Step 4: After we have done this, we will create a new branch and add all the large files there and push the new branch into the remote repository.

Tip: If you don’t know how to set up a remote branch and push code to it, then go through Git tutorial 

Step 5: Now let us clone the repository from the remote.

Step 6: After cloning if we look at the size of the cloned repository and the original repository we can see that there is a big difference between their sizes.

The original Repository is as follows: 

Cloned Repository is as follows: 

So, here we can see that the original repository has a size of 9.2 MB but the cloned repository is only 172KB as the Git-LFS only put tiny pointers of those large image files and not the actual images on the cloned repository.

Step 7: Now if we check out to that branch where the large files are present, then at that moment only the actual files will be downloaded from the remote servers.

Here is the terminal shell pictorial depiction after executing the above commands as follows:  

As we can see from the screenshot after we checkout to the large_file_branch then at that moment the actual files are getting downloaded.


Git – LFS (Large File Storage)

Git is a version control system widely used for tracking changes in source code during software development. However, it has limitations when dealing with large files. Enter Git Large File Storage (LFS), a Git extension designed to handle these large files efficiently. In this article, we will learn more about Git LFS and how to use it effectively.

Similar Reads

What is Git LFS?

Git LFS (Large File Storage) is an open-source extension for Git that helps manage large files by replacing them with lightweight pointers within your Git repository while storing the actual file contents on a remote server. This approach keeps the repository size manageable and ensures that performance remains optimal, even with large files....

Why Use Git LFS?

1. Efficient Storage Management:...

How Does Git LFS Work?

Git LFS replaces large files in your repository with tiny pointer files. These pointer files contain metadata about the original large files. The actual large files are stored in a dedicated LFS server. When you check out a branch, Git LFS automatically replaces the pointer files with the corresponding large files from the LFS server....

Steps to Implement Git LFS

In order to use Git LFS, first, we need to install it on our system. We can use the following command to do so....

Contact Us