Versioning Large File in Git

I want to introduce you Git LFS, it is a command line extension and specification for managing large files with Git. LFS is great for large, changing files, there is basically a text pointer to the large file archived some place else.

Usually we store large file or object in artifactory, for example: jFrog, Nexus, etc.

Install Git LFS

Note: you need to install Git LFS if you git pull from a remote repository that has it

For example, I am working on a RHEL machine. First go to source page, follow the installation guide to install:

This will create a yum repos for git-lfs:

1
yum install -y git-lfs

you can see git-lfs is installed in your machine:

Once downloaded and installed, set up Git LFS and its respective hooks by running:

1
git lfs install

Note: You’ll need to run this in your repository directory, once per repository.

Track Large File

Select the file types you’d like Git LFS to manage (or directly edit your .gitattributes). You can configure additional file extensions at anytime.

1
git lfs track "*.tar.gz"

Note: run this track command at the top level of your repository, then you need to git add .gitattributes file

Manage Large File

Then, just do normal git add and git commit to manage your large size file.

1
2
3
git add *.tar.gz
git commit -m "add tar.gz file"
git push origin <your branch>

Actually, you can check the large files you managed by running:

1
git lfs ls-files
0%