Unity Project .gitattributes with Merge Settings
Configure .gitattributes for Unity game development with YAML merge drivers, binary asset handling, and proper scene file settings.
Detailed Explanation
Unity and Git
Unity projects are notoriously challenging with Git because Unity serializes scene files, prefabs, and other assets as YAML. These files look like text but have a structure that standard merge algorithms handle poorly. The merge=unityyamlmerge driver and careful attribute configuration are essential.
Recommended Configuration
# Auto detect
* text=auto
# Unity YAML files
*.unity merge=unityyamlmerge eol=lf
*.prefab merge=unityyamlmerge eol=lf
*.asset merge=unityyamlmerge eol=lf
*.meta merge=unityyamlmerge eol=lf
*.mat merge=unityyamlmerge eol=lf
*.anim merge=unityyamlmerge eol=lf
*.controller merge=unityyamlmerge eol=lf
*.overrideController merge=unityyamlmerge eol=lf
*.playable merge=unityyamlmerge eol=lf
*.mask merge=unityyamlmerge eol=lf
*.physicMaterial merge=unityyamlmerge eol=lf
*.physicsMaterial2D merge=unityyamlmerge eol=lf
*.lighting merge=unityyamlmerge eol=lf
# C# source
*.cs text diff=csharp
# Shaders
*.shader text
*.cginc text
*.hlsl text
*.compute text
*.glsl text
# Config
*.json text
*.xml text
*.yml text
*.yaml text
# Binary assets
*.png binary
*.jpg binary
*.jpeg binary
*.psd binary
*.tga binary
*.tiff binary
*.gif binary
*.bmp binary
*.fbx binary
*.obj binary
*.3ds binary
*.dae binary
*.blend binary
*.wav binary
*.mp3 binary
*.ogg binary
*.aiff binary
*.ttf binary
*.otf binary
*.dll binary
*.exe binary
*.so binary
*.dylib binary
*.unitypackage binary
Setting Up UnityYAMLMerge
The merge=unityyamlmerge attribute requires configuring Git to use Unity's merge tool:
# In .gitconfig or .git/config
[merge "unityyamlmerge"]
name = Unity YAML Merge
driver = '/Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge' merge -p %O %A %B %A
recursive = binary
Why eol=lf for Unity Files?
Unity's version control integration expects LF line endings. Using CRLF causes Unity to constantly re-serialize files, creating unnecessary changes and merge conflicts. Force eol=lf for all Unity YAML files.
Use Case
Game development teams using Unity with Git must configure these attributes to prevent scene corruption, enable proper YAML merging, and handle the many binary asset formats (textures, models, audio) that Unity projects contain.