Git with Unity#

Git is the most popular solution among developers and is also well-suited for Unity projects. It’s a great alternative to Perforce, Plastic SCM, or SVN and has the biggest ecosystem of tools and cloud services. Git is wonderfully suited for Unity, since Unity’s scene files are text-based. No plugin is needed for Unity either.

File locking#

By default, Unity does not respect the read only property of a file. Anchorpoint places a script in the Assets/Anchorpoint folder so that Unity does not overwrite read only files. You can put this script in your Editor Scripts folder.

Here you can download this script if you are missing it.

Unity’s Smart Merge Tool#

When you both work on the same scene but on different objects, your changes can be merged. Git can merge text files, but it is not intelligent enough to merge Unity scenes. For that, you have to use their UnityYAMLMerge tool. To use it, you have to modify the .gitconfig file.

  1. Open your Unity project in Windows Explorer.

  2. Make hidden files visible.

  3. Open a .git folder and open the config file in a text editor.

  4. Add the following code:

tool = unityyamlmerge

[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = "'path to UnityYAMLMerge'" merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"

“path to UnityYAMLMerge” should be replaced by the real path to the UnityYAMLMerge.exe on your computer. Usually, you can find it under: “C:/Program Files/Unity/Hub/Editor/2021.3.21f1/Editor/Data/Tools/UnityYAMLMerge.exe”. Make sure that you use forward slashes (/) and not backslashes (\) like Windows is doing.

You have to navigate to the place where your UnityYAMLMerge.exe is located. Make sure to use forward slashes and not backslashes.