Git LFS, simple tutorial
The Git LFS (Large File Storage) is a git extension, programmed in Go, which was created by developers at Atlassian and Github. This tool aims to avoid a limitation of the Git version control system, that it performs poorly when versioning large files, especially binaries. It does this by storing large files in a separate location from your repository and placing a pointer file in your repository directing to its location.
Down below, we have a list of extensions that are binary file formats:
- Images: jpg, png, gif, bmp, tiff, psd
- Videos: mp4, mkv, avi, mov, mpg, vob
- Audio: mp3, aac, wav, flac, ogg, mka, wma
- Documents: pdf, doc, xls, ppt, docx, odt
- Archive: zip, rar, 7z, tar, iso
- Database: mdb, accde, frm, sqlite
- Executable: exe, dll, so, class
To use the Git LFS in our machine, first we need to install the Git LFS (in Windows we can do that using Chocolatey package manager):
choco install git-lfs
After that, we can complete the instalation using the command below:
git lfs install
How it works?
This section is based on the Atlassian Git LFS Tutorial
- When you add a file to your repository, Git LFS will replace the content with a pointer, and stores the file contents in a local Git LFS cache.
- When new commits are pushed to the server, the Git LFS files referenced by the newly commit are transferred from the local Git LFS cache to the remote Git LFS storage.
- When a commit that contains Git LFS pointers is checked out, they are updated with files from the local Git LFS cache, or downloaded from the remote Git LFS storage.
Using Git LFS
In Fork, we can use the Git LFS in a repository like we use GitFlow. First, we need to initialize Git LFS in the repository:
After that, we can track the files by pattern or anything else (in the image below, we’re tracking all .dll and .exe files):
The files will be replaced by new files (that use LFS) and a .gitattributes files will be created with the commands down below.
After this stage, we need to add, commit and push the files to origin branch. Thus, the file will be marked by LFS Tag, like thhis example:
Hope you guys like this simple tutorial! ❤😎