Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GregLevenhagen/254abefa4b51c4aa444948b125f8f692 to your computer and use it in GitHub Desktop.
Save GregLevenhagen/254abefa4b51c4aa444948b125f8f692 to your computer and use it in GitHub Desktop.
Using Git with Unity, Visual Studio, HoloLens and Handling Merges

Using Git with Unity, Visual Studio and optionally HoloLens

This will help with merging of Scenes, Prefabs and Assets when working in Unity team environments.

Place the gitignore and gitattributes files in the base directory of your git repository. The gitconfig contents can go into your global .gitconfig file, in the repo's .git/config file or a custom .gitconfig file. A custom .gitconfig will need to be manually configured by each team member, even if it's in tracked in the repo because it's a security vulnerability.

The gitignore file contains a mashup from the HoloToolkit-Unity gitignore, along with GitHub/gitignore files for Unity and Visual Studio.

The gitconfig file tells git to use Unity's Smart Merge (aka UnityYAMLmerge), which is installed with Unity, to handle YAML merges.

The gitattributes file tells git that those files should be treated as binary and handled by the UnityYAMLmerge tool.

Your Unity project settings should be configured for asset serialization set to Force Text. Menu options should be something similar to Edit -> Project Settings -> Asset Serialization -> Mode.

Inspired by
  1. Ikalou's Gist
  2. StackOverflow question on Unity's SmartMerge
  3. StackOverflow question on gitconfig
  4. This blog post
# stop git from trying to merge these by setting them to binary.
# should have Unity->Edit->Project Settings->Asset Serialization->Mode set to Force Text.
*.unity binary
*.prefab binary
*.asset binary
# tell git to use the built in unityyamlmerge tool for merging
[merge]
tool = unityyamlmerge
[mergetool "unityyamlmerge"]
trustExitCode = false
keepTemporaries = true
keepBackup = false
path = 'C:\\Program Files\\Unity\\Editor\\Data\\Tools\\UnityYAMLMerge.exe'
cmd = 'C:\\Program Files\\Unity\\Editor\\Data\\Tools\\UnityYAMLMerge.exe' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
# For Unity, Visual Studio and HoloLens
# Modified from https://github.com/GregLevenhagen/HoloToolkit-Unity/blob/master/.gitignore
# =============== #
# Unity generated #
# =============== #
[Bb]in/
UnityGenerated/
[Aa]pp/
[Uu][Ww][Pp]/
project.json
project.lock.json
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
obj/
/*.csproj
/*.sln
*.ipch
*.opensdf
*.sdf
*.obj
*.tlog
*.log
*.idb
*.opendb
WSATestCertificate.pfx
WSATestCertificate.pfx.meta
# ===================================== #
# Visual Studio Code (VSCode) generated #
# ===================================== #
.vscode/*
# Modified From https://github.com/github/gitignore/blob/master/Unity.gitignore
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
Assets/AssetStoreTools*
# Visual Studio cache directory
.vs/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
# Unity3D generated meta files
*.pidb.meta
# Unity3D Generated File On Crash Reports
sysinfo.txt
# Builds
*.apk
*.unitypackage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment