Smaller Git Repo Size Using Git LFS<br> (šŸ¤” Xcode Assets)

Smaller Git Repo Size Using Git LFS
(šŸ¤” Xcode Assets)

Summary

If you want to see a comparison of Git with and without Git LFS, see this section below.

Have you ever gone to clone a repository (repo), and ended up just sitting there staring at the slow moving percentageā€¦šŸ˜¶?

Yeah, me too ā€”Ā this may help!

Often times with a project, like with Xcode projects, we check assets into Git so that our app has immediate access to those files (images, videos, audio files, etc.). Over time, changes to those assets may end up bloating your repoā€™s size1 šŸ˜…. When this happens, Git operations like cloning can take an unfortunate amount of timeā€¦

Luckily, there is a Git extension called Git Large File Storage (LFS) to help manage your large files (without changing your Git workflow šŸ˜), which means:

1. Git is less effective at compressing binary files, and therefore ends up storing near duplicates of those files. Read more.


Getting Started with Git Large File Storage (LFS)

There are different ways to install Git LFS, but if you are on a Mac: brew install git-lfs

Setup is pretty straight forward. Do the following to add files or folders to Git LFS:

Donā€™t forget to make sure that installing Git LFS is part of your setup README for project :).
See the first bullet under considerations below for more details.

Thatā€™s it šŸŽŠ ā€”Ā Go about your normal Git workflow like before, and the marked files will now be managed by GitĀ LFS!

Existing Files - For The Maximum Benefit

Caution: The below steps result in a destructive git repo operation, and should be done carefully After performing the below steps, all members of your team will need to delete their local repos and re-clone the project repo. This is because their existing local repos will no longer be compatible with the newly force pushed master.

For an existing repo, you will get the biggest gain from using Git LFS by retroactively applying Git LFS to files and folders. Here is how to integrate Git LFS as if you have been using it since the beginning of your project.

For setup, do the same steps as before, but for files that are already being tracked in Git:


Comparison of Git with (and without) Git LFS

As an example I created an example project (https://github.com/jasonzurita/Git-LFS-Test) to compare Git with and without Git LFS.

The result was that cloning the project took close to half the time (~15s vs ~30s) when directly cloning the branch using Git LFS ā€”Ā and this is for a small example project. Imagine the potential impact for more mature projects with lots of file changes of this nature!!

To try this yourself:

You can also see the difference Git LFS makes in the Git repo size here:

A comparison of repo size between regular git and git lfs

Considerations


Thank you for reading!

Feel free to reach out on Twitter ā€”Ā cheers!

rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora