Skip to content

Instantly share code, notes, and snippets.

@djcsdy
Last active March 26, 2024 20:04
Show Gist options
  • Save djcsdy/1f9cc264dc56c16bf2d9d228a1db78a5 to your computer and use it in GitHub Desktop.
Save djcsdy/1f9cc264dc56c16bf2d9d228a1db78a5 to your computer and use it in GitHub Desktop.
Unity with source control

In the Unity editor:

  1. Edit -> Project Settings -> Editor
  2. In the inspector panel, set:
  3. Version Control -> Mode: Visible Meta Files
  4. Asset Serialization -> Mode: Force Text

“Visible Meta Files” causes Unity to place .meta files next to each of your assets. It’s important to check these files into version control because they contain the settings associated with those assets that you set in the Unity editor.

“Asset Serialization: Force Text” causes Unity to write its .meta and other files in a more-or-less human-readable text format, which makes it a lot easier to understand what has changed when you look at version control logs. Also it’s feasible to merge these text files by hand, whereas it’s not really possible to do that with Unity’s default binary file format.

Create a .gitignore file in the root of your project with the following contents:

/Temp
/Library
/Obj
/UnityGenerated
/Build
/Builds
/*.sln
/Assembly-CSharp.csproj
*.suo
*.user
*.userprefs

Most of the stuff in the above ignore file is stuff generated by Unity when you open or build your project, so you don’t need to check that stuff in. Usually in a .NET project you would check in the *.sln and *.csproj files, but in a Unity project Unity will generate those so it’s best not to check them in.

*.suo files are generated by Visual Studio when you open your project, you don’t need to check that in. (MonoDevelop probably also generates these files but I’m not sure).

*.user and *.userprefs contains Visual Studio settings that are specific to an individual PC, you shouldn’t check these in. (MonoDevelop probably also generates these files but I’m not sure).

If you use Blender, add the following to the .gitignore also:

*.blend1
*.blend1.meta

Create a .gitattributes file in the root of your project with the following contents:

*.sln text eol=crlf
*.csproj text eol=crlf
*.anim text eol=lf
*.asmdef text eol=lf
*.asset text eol=lf
*.controller text eol=lf
*.mat text eol=lf
*.meta text eol=lf
*.overrideController text eol=lf
*.prefab text eol=lf
*.preset text eol=lf
*.spriteatlas text eol=lf
*.unity text eol=lf
*.mixer text eol=lf
*.renderTexture text eol=lf
*.json text eol=lf
*.xml text eol=lf

This ensures that .NET project files are stored with CRLF line endings, which is required by the .NET spec. It also ensures that Unity *.asset files are stored with LF line endings. Unity always uses LF line endings for these files regardless of platform.

The .gitattributes file is not mandatory, and nothing will break if you don’t include it. However, if you don’t, then depending on your platform these files may show as having changes whenever Unity rewrites the file, even if the contents of the file are the same, which can be very annoying.

@Michaelwolf95
Copy link

@Last8Exile Ok, well, it's working for me as-is. 👍

@9-winter
Copy link

@djcsdy Thank you so much ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment