Setting up Git & Unity #
- We need .meta files in the git repo.
- We should ignore auto-generated files: the Library folder in particular will completely bork a Git repo
- Users could work in different versions of Unity, but it’s heavily discouraged, and can lead to unpredictable consequences.
- If you use Unity’s support for proprietary-files-auto-converted-into-assets, such as using “.blend”, “.maya”, or “.psd” imports (for Blender, Maya, and Photoshop, respectively), then that software needs to be installed on all the machines using the project. See this manual for details, but for this reason it’s recommended to export to FBX when in production.
- You should probably configure Git LFS for images, models, and other large file types.
- Unity has a tool (called “UnityYAMLMerge”) that can merge scene and prefab files much better than the default git merge behavior. See the Smart Merge manual page for info how to set it up.
Setup The Local Repository #
- Create an empty Unity Project, or use an existing project.
- Initiate a New Repository in the root directory.
- Add a .gitignore file for Unity.
- You can use this one, which is worth reading through. The most important things to tell git to ignore are the Library, Temp, and Logs folders, and the .sln solution file.
- Save that above link to a file, and change it’s name to “.gitignore”. Where the file has no name, and the file extension “gitignore”.
- (Optional) Setup Git LFS.
- This is not a guide on git LFS, but I will note that you don’t want to use Git LFS for scene files, which some git LFS guides tell you to do. Instead, a better solution is to use Unity’s YAMLMergeTool to deal with the complexities of scene files.
- Stage and Commit the initial project.
- We want to commit our Assets (and SampleScene), the packages folder, the ProjectSettings folder.
Setup the Remote Repository #
- In GitHub, select ‘Create a New Repository’.
- Give it a name and description.
- Do not add a readme or a .gitignore. We want this to be a completely empty repository.
- After creating the repository, it should be empty. The project page should say something like “Quick Setup…”, with some advice on how to add code.
- Copy the URL (the one that ends in .git) from that Quick Setup box on the empty repository page.
- In our Git client, add the repository url as a remote.
- Push our initial changes, double checking we are not committing anything in the Library folder or auto-generated IDE-config folders (like .idea or .vscode).
Add Collaborators #
In GitHub, go to the project page, go to settings, collaborators, and Invite all of your teammates. They will need to accept the invitation, which is easily done through the auto-sent email.
Collaborators need only Clone the repo, like normal. Once cloned, choose the “Open” option from Unity Hub, and select the projects root folder that you just downloaded.
Git Software #
Keep in mind that git is just metadata that lives with your project. It can be deleted, restarted, and moved around no matter what git tool you are using to call the commands. You can learn the command line commands, or use piece of software that is basically just a graphical interface for calling the same commands. You can have and use multiple pieces of git software at the same time.
Some Git GUI software packages will keep their own copy of the actual “git” command line software. Others will require you to install git separately on your system.
Git GUI Software #
- Git Fork (What I personally use)
- GitHub Desktop (Works well for GitHub, not very feature-rich)
- SourceTree (Popular, Free, Good)
- GitKraken (One of my students swears by this one)
See here for a larger list.