Using Unity with Git, made painless for everyone.

GitMerge for Unity is a free, open source Unity Editor tool that allows you to merge scene and prefab files. This solves the main problem you currently get when using Git to work with Unity.

About

Unity offers a few solutions for collaborative teamwork. These do not necessarily stick to the standard you're used to. So... why not use Git?

You'll have to take these two things into account in order to get started:

  1. Setup a good .gitignore, like this one.
  2. Get yourself a mergetool for scenes and prefabs.
    That's where GitMerge for Unity is supposed to come in.

GitMerge for Unity is licensed under the GPL2.0 license.

How to install

To use GitMerge for Unity, go to the project page and clone the repository into your Assets Folder.

Next, you make sure that Git doesn't try to merge scenes and prefabs automatically, since this usually leads to broken files with Unity scenes and prefabs.

You have two ways to do that. The first one is to make sure that "Asset Serialization" is set to "Mixed" or "Binary". Unity will save scenes and prefabs as binary files and Git won't touch them.

If you want your files serialized as YAML files, you can alternatively add a .gitattributes file that tells Git to handle said filetypes as binary files, even though you want Unity so save them as YAML files.
That .gitattributes file could look like this:

# .gitattributes

*.unity binary
*.prefab binary
*.asset binary

# etc.

That's it, you're ready to go!

How to use

GitMerge for Unity is an open source software and is constantly being developed. If you find something that could be improved, please feel free to help!

Start merging

GitMerge for Unity comes as an opt-in merge tool. It is not integrated into Git as an automatic merge tool since merging scenes and prefabs is something you'd never want to have done automatically.

First off, you create your merge conflict the way you usually do. Once you're in Git's MERGING state, open the GitMerge window in Unity (Window → GitMerge).

This is what a scene merge situation can look like.

The BoxCollider component of the "Cube" GameObject has been automatically merged to the default setting ("keep it").
The user has decided to use "their" version of Transform.LocalPosition, but "our" version of Rigidbody.Interpolate and BoxCollider.IsTrigger.
The other two conflicts have not been addressed yet.

Merge a scene

To merge a scene, open it the usual way. Then, in the GitMerge Window, click "Start merging this scene". When there is an active merge conflict, the tool will find the differences between the currently opened version of the scene and "their" version.

You will then get a list of so called "MergeActions" in the tool window. Each MergeAction solves one point of conflict between the two scenes.
To do this, you will be offered two to three options every time:

You can choose to click the left button to use our version, the left button for their version, or enter a new value in the middle. Either way, the MergeAction line will turn from red (unmerged) to green (merged). MergeActions that have been automatically merged to a default (like keeping a Component that "their" version doesn't have) are marked yellow.

You can, of course, continue to edit the scene in a normal way during merging. It is not recommended to delete GameObjects that might be part of a MergeAction though.

When all MergeActions are flagged as merged, you can click on "Apply merge".
The scene will be saved and marked as merged for git. Since there could be more merge conflicts, this will not automatically commit.
You'll have to commit your merge manually at some point from now on.

Merge a prefab

Merging a prefab pretty much works like with a scene.

While in a merge conflict, open the "Merge Prefab" tab and drag your prefab into the field.
A new scene will be opened. This scene contains an instance of said prefab. You'll get the same type of list you already know from scene merging. Merge your conflicts and see the result on the prefab instance.

When you hit "Apply merge" when done, you will be returned to the scene you were in before. The prefab file will be added to the Git stage, but remember that you'll have to commmit the merge yourself.

Active development

GitMerge for Unity is an open source tool that is being actively developed. You can head over to the project page, check out issues, fork, and make pull requests.
If you find a bug or something to improve, but cannot fix/implement it yourself, feel free to tell me about it.

To see what's up next, have a look at the project's issue page.