Click Here for Part 2— where we go through the process of a first commit and the routine commands you’ll use daily.
Game Development is more than Code
Git is over 16 years old, and originally designed for coders. As such it has a few built-in limitations.
Namely, GitHub has a 1 GB storage limit and 100MB file size limit.
If you’re just working with code you’ll never reach GitHub’s limits, but with Unity3d projects, we have art, music, models, textures, and more to commit so hitting that cap is pretty easy.
Modern AAA games like Call of Duty release as 133.6GB projects!
Even small indie games are typically 2GB in size.
And once you know how storage is calculated you’ll realize how little 1GB can actually be.
That’s where Git LFS comes in though.
LFS stands for Large File Storage and it is a plugin that allows us to store large game assets easier. There are additional benefits, but again we don’t need to be too concerned about that for our needs.
Understanding Git LFS Storage Calculations
GitHub’s LFS free tier allows 1GB of free storage, and then they have a paid tier which at this time is $5/month for every 50GB of storage you need.
BUT! If you remember how we said that Version Control Systems store every change you make in a retrievable format. That way you can go from released version 1.0 with the polished textures and animations, all the way back to the 1st-day prototype be it a code file, 3D model, or music.
This can lead to a potential issue as when you update any large file like a 3D model, it needs to save a completely new copy into GitHub to be able to create those retrievable versions.
A Storage Calculation Example:
If you commit a 30MB model you just made, and then tomorrow you make a tweak to the model file requiring you to now commit a change, well now that’s a new “30MB model”. So we’ve technically used 60MB of storage. And even if tomorrow in a new commit we decide to delete that model, we’re still using those 60MB of storage as they’re still stored in older versions.
You can see how that can quickly scale up into needing larger and larger storage, especially if your team isn’t conscious of what they are committing to GitHub. Luckily it’s not typical to do minor tweaks to models daily like this once in Unity, and there are advanced commands to clean the Remote Repo on GitHub.
Just knowing how Git LFS storage is calculated helps ensure you keep your GitHub Repo clean. As nothing is worse than having a teammate accidentally upload 50 hi-res models from an asset pack that may not even be used in the final product.
Is GitHub LFS the only option?
There are other services out there besides GitHub such as GitLab, BitBucket, and more. Some are cheaper, others more expensive, with pros/cons mixed in. As well as solutions through LFS is fairly straightforward and inexpensive at the end of the day.
If you are trying to save where you can before paying monthly, GitLab and BitBucket do offer 10GB initially on their free tier instead of 1GB and you can always learn to switch to a new service within a day.
For this tutorial, we’ll stick with GitHub though as the installation process is similar enough for all solutions.
Installing Git LFS
Installation is surprisingly easier than Git for what we need.
Run the .exe, accept the agreement, click next, and well it’s installed to your computer! Now we just need to activate it in our project Repo that we made in Part 1.
Activating LFS for our Project Repo
Simply go to the project folder in GitBash. If you’ve forgotten the command to do this you can revisit Part 1 or use this handy trick of right-clicking in the project and selecting GitBash.
Now we simply type in the command
git lfs install
LFS is now active! Now we just have to configure it.
Configuring LFS with .gitattribute
LFS by default won’t actually do anything until we tell it to, luckily this is pretty straight forward and like .gitignore we can use someone else’s Unity3d template to get basically all the files we’d want unless you are doing something super custom.
BUT before using a template, let’s go through adding one just so we know how to customize our LFS setup.
To tell it to handle a file type we simply use the command “track” followed by “*.filetype”.
* is a wildcard symbol basically meaning in this context, “any filename is fine” as we just care about unique file types. And by filetype we mean files that end with .mp3 .wav .psd and all the other large asset files found in games.
So let’s make git LFS keep track of all of our .psd (photoshop files) which can get rather large.
git lfs track "*.psd"
this has now added a new file to our project called .gitattributes! If we can open it we can see the line with *.psd added in with some other stuff talking about lfs.
Now doing this manually for all files is tedious so let’s go grab that template! We can literally just replace our .gitattributes with the content below
.gitattributes Template for Unity3d
Just copy, paste, save it into your .gitattributes we created.
Now We Just Commit
Everythings set up, now we just do our routine commit process.
git add .
git commit -m "Setup Git LFS"
And now it’s on GitHub!
LFS will now handle our game asset files, and if we hit the 1GB limit we can purchase more storage from GitHub by clicking here.
Workflow Best Practices
Congrats Setup is done!
You could comfortably work with Git as is and get a project done.
This means we can now get into best practices so you get the project done faster!
While every studio has its own preferred setups there are some typical standard ones, the one I’ll be covering is Feature Branching.