Git LFS Crash Course

Ignatius Bagussuputra #tech#git#crash-course
Article Index

Git LFS is an open source Git extension for versioning large files (e.g. audio, video, and graphics) with Git by replacing these large files with text pointers that are tracked by Git, while storing the file contents on a remote server like GitHub.

This extension is really useful when working on a project with large files that are updated frequently, such as assets in a game project. It allows us to keep the repository size small while still being able to version the large files, meaning faster cloning and pulling of the repository. We also don’t need to worry about cleaning up the repository history to remove the large files after they are no longer needed.

We do have to keep in mind that Git LFS needs a remote server to store the large files, so we’re fully dependent on the server for their availability, storage, and bandwidth. If you rarely or never update the large files, then you can ignore this extension knowing you’re not missing out on anything.

Installation

To install Git LFS, we can run the following command…

	
git lfs install

Then we can track the large files (we’re using “mp4” files as an example here) by running…

	
git lfs track "*.mp4"

This will add or generate a .gitattributes file that you’ll need to track and commit. Commit the rest of the changes, push it, and you’re done!

Uninstalling

To uninstall Git LFS, we can run the following command…

	
git lfs uninstall

Then go to your .gitattributes file and remove the lines that were added by Git LFS (if it’s everything, then you can safely delete the file)

	
.gitattributes
# examples this file might have *.md linguist-detectable -*.mp4 filter=lfs diff=lfs merge=lfs -text -*.png filter=lfs diff=lfs merge=lfs -text -*.jpg filter=lfs diff=lfs merge=lfs -text -*.jpeg filter=lfs diff=lfs merge=lfs -text

Re-track and add the files that were previously tracked by Git LFS by running…

	
git add --renormalize .

commit the changes, push it, and you’re done!


Reference(s):

See something to improve or fix? In the spirit of open-source, you can create a new issue or contribute directly to this article by sending a Pull Request on GitHub!