Unity3D scenes and prefabs cannot not be merged automatically by default. Working on one scene / prefab at the same time can cause issues when a merge conflict happens. Usually that means that one version needs to be discarded or the files need to be merged manually (which isn't easy).
However, Unity provides the UnityYAMLMerge tool with each Unity installation to merge scenes and prefabs semantically for manual setup. This is also called Smart Merge. The tool can be accessed from the command line and is also available to third-party version control software like Git, etc. To setup the smart merge for Git, follow the following steps.
Add the following text to your .git/config
file inside your project folder or to your <path to user folder>/.gitconfig
.
[merge]
tool = unityyamlmerge
[mergetool "unityyamlmerge"]
trustExitCode = false
cmd = '<path to unity folder>\Editor\Data\Tools\UnityYAMLMerge.exe' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
The smart merge only works when different changes doesn't occur in the same gameObjects / components. If so, there still will be a merge conflict which needs to be solved manually. To do that we need to configure a fallback merge tool. We can use any, but here I decided to use the free visual appealing merge tool P4Merge. This can be downloaded here: https://www.perforce.com/downloads/visual-merge-tool
Here is how to hook up the merge tool as global merge tool. Type the following in the cmd:
git config --global merge.tool p4merge
git config --global mergetool.p4merge.path 'C:/Program Files/Perforce/p4merge.exe'