Enable Git LFS for a Unity project

Creating a game requires a lot of assets – 3d models, sounds, texture, etc., which Git wasn’t meant to handle. But there is a solution to this problem – Git LFS!

Git Large File Storage was created to handle large files, as the name implies. This extension is great for storing all sorts of assets like 3d models, textures, sounds, etc.

Thanks to LFS, changing those files won’t negatively impact your repository size!

Have you set Git for your project already? If not, I wrote a post how you can set git for a Unity project!

What’s Git LFS? ?

Tracking big binary files with Git is problematic, especially when you modify them often. Each time you will change something in such a file, Git will have to upload a whole file, and not just a piece of it like it does with text files.

Because of that behavior, the size of your repository will grow really quickly, and it’ll be harder to work with it as fetching and pulling commits will be more resource-intensive.

The solution for that problem comes in the form of Git LFS extension. Using LFS doesn’t change anything to your workflow with the Git repository. This is just a transparent layer you don’t really need to think about.

LFS uses separate space on the server, and it handles a little bit differently than your regular code. You can think about it as a Google Drive for your assets, but it’s integrated with Git.

Thanks to that, when you clone the repository, you won’t download those big files, but you will only have the current, most recent version of such an asset.

How to enable it in my project? ?

It’s not that complicated! Or at least when you use SourceTree. ?

The first thing we need to do is to initialize Git LFS.

Initialize Git LFS.
Start using Git LFS.

The second step will be to pick file extensions that will be tracked by Git LFS.

Add file extensions.

Here is a little list you can use for LFS tracking:

# .gitattributes

# Images
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.psd filter=lfs diff=lfs merge=lfs -text
*.ai filter=lfs diff=lfs merge=lfs -text
*.tif filter=lfs diff=lfs merge=lfs -text
*.tga filter=lfs diff=lfs merge=lfs -text
*.cubemap filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.hdr filter=lfs diff=lfs merge=lfs -text

# Fonts
*.otf filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text

# Audio
*.aif filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.ogg filter=lfs diff=lfs merge=lfs -text

# Video
*.mp4 filter=lfs diff=lfs merge=lfs -text
*.mov filter=lfs diff=lfs merge=lfs -text

# 3D Objects
*.3dm filter=lfs diff=lfs merge=lfs -text
*.3ds filter=lfs diff=lfs merge=lfs -text
*.blend filter=lfs diff=lfs merge=lfs -text
*.c4d filter=lfs diff=lfs merge=lfs -text
*.collada filter=lfs diff=lfs merge=lfs -text
*.dae filter=lfs diff=lfs merge=lfs -text
*.dxf filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.jas filter=lfs diff=lfs merge=lfs -text
*.lws filter=lfs diff=lfs merge=lfs -text
*.lxo filter=lfs diff=lfs merge=lfs -text
*.ma filter=lfs diff=lfs merge=lfs -text
*.max filter=lfs diff=lfs merge=lfs -text
*.mb filter=lfs diff=lfs merge=lfs -text
*.obj filter=lfs diff=lfs merge=lfs -text

# Other
*.a filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.dll filter=lfs diff=lfs merge=lfs -text
*.rns filter=lfs diff=lfs merge=lfs -text
*.unitypackage filter=lfs diff=lfs merge=lfs -text

This is definitely not a complete list, but it’s a great place to start. ?

When you initialize LFS for your repository, you may see that all files with extensions you’ve added now are marked as changed.

You can go and select all the files, as now they will be tracked by LFS. ❤️

These files are now in Git LFS.

Summary ?

Git LFS is a transparent solution that helps with handling large (binary) files while reducing your repository size. ?

Did you face a problem with committing big files? Did your repo grow too big? Do you think Git LFS can help with your problem?

Let me know in the comment section below! And if you know someone that can get some help, share a link with him to this post. I’ll really appreciate that! ?

If you are interested in getting emails when I release a new post, sign up for the newsletter!

I’ve also initialized Lig LFS at at my public repository for Unity Git Setup. ?

Hope to see you next time! ?

4 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x