Using Git for Unity 3D projects
I was recently asked by a collaborator why we’d switched to using Git for our Unity projects, and I thought the bullet points I passed to him might serve useful to someone else considering the switch, so here we go:
We previously used Asset Server (via VPN) but switched to Git due to a number of advantages, including:
- Easy remote access from anywhere, highly performant on most networks. Important for our highly distributed team, and frequent access requests from non-team individuals.
- Supports branching, allowing us to safely work on multiple features without breaking our main build. This has become particularly important to us since we’ll need to be able to support a main release with hotfixes while safely working on future version features.
- Excellent support for tagging and selective reverts. Has already saved us a number of times :)
- Supports offline work beautifully, it’s still possible to commit when the network goes down, move onto other tasks, and handle merges later.
- History is available offline as well.
- Diff based versioning, as opposed to Asset Server’s timestamp based versioning.
- Better merge and conflict handling.
- No need for additional per seat client licensing.
- 3rd party cloud hosted packages available (GitHub in our case) to take management off our hands.
It’s by no means perfect of course, and does take some adjustments to workflow, for example:
- Know what belongs in Git and what doesn’t. Basically everything in /Assets and /ProjectSettings, nothing from /Library or other temp locations, and nothing that is frequently autogenerated like Mono projects.
- .meta files must always be committed with their assets, some simple rules:
- Always open the project in Unity before a commit, to allow it to update metas.
- If you add an asset or folder, it’s up to you to commit the meta
- Move/delete objects in Unity, not the filesystem, so it updates metas accordingly (git detects these actions correctly, moves actually show up as moves in history)
- If you delete an asset or folder, it’s up to you to commit the meta deletion
- Always delete folders that no longer contain assets and commit the meta deletion
Regardless of workflow, there are some difficulties/disadvantages that need to be taken into account when considering the switch:
- Since each user clones the entire repository, much more disk space is required.
- It’s essential for all users to understand the commit/pull/resolve conflicts/push process, or they can potentially cause serious damage.
- Not built into Unity, so one more tool to learn.
- Since game project assets are so large, occasional cleanup is needed to keep repo size down.