Skip to content

Instantly share code, notes, and snippets.

@thomashope
Last active October 5, 2022 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomashope/d7d0edebb1dbe49fcc1f5a9991d2c04c to your computer and use it in GitHub Desktop.
Save thomashope/d7d0edebb1dbe49fcc1f5a9991d2c04c to your computer and use it in GitHub Desktop.
Git setup for Unity projects
# Macro for Unity YAML-based asset files.
[attr]unityyaml -text merge=unity diff
# Macro for all binary files that should use Git LFS.
[attr]lfs -text filter=lfs diff=lfs merge=lfs
# Default to auto-normalized line endings.
* text=auto
# Code
*.cs text diff=csharp
# Unity Text Assets
*.meta unityyaml
*.unity unityyaml
*.asset unityyaml
*.prefab unityyaml
*.mat unityyaml
*.anim unityyaml
*.controller unityyaml
*.overrideController unityyaml
*.physicMaterial unityyaml
*.physicsMaterial2D unityyaml
*.playable unityyaml
*.mask unityyaml
*.brush unityyaml
*.flare unityyaml
*.fontsettings unityyaml
*.guiskin unityyaml
*.giparams unityyaml
*.renderTexture unityyaml
*.spriteatlas unityyaml
*.terrainlayer unityyaml
*.mixer unityyaml
*.shadervariants unityyaml
*.preset unityyaml
*.asmdef -text diff
# Unity Binary Assets
*.cubemap lfs
*.unitypackage lfs
# Note: Unity terrain assets must have "-Terrain" suffix.
*[Tt]errain.asset -unityyaml lfs
# Note: Unity navmesh assets must have "-NavMesh" suffix.
*[Nn]av[Mm]esh.asset -unityyaml lfs
# Image
*.jpg lfs
*.jpeg lfs
*.png lfs
*.apng lfs
*.atsc lfs
*.gif lfs
*.bmp lfs
*.exr lfs
*.tga lfs
*.tiff lfs
*.tif lfs
*.iff lfs
*.pict lfs
*.dds lfs
*.xcf lfs
*.leo lfs
*.kra lfs
*.kpp lfs
*.clip lfs
*.webm lfs
*.webp lfs
*.svg lfs
*.svgz lfs
*.psd lfs
*.afphoto lfs
*.afdesign lfs
# Audio
*.mp3 lfs
*.ogg lfs
*.wav lfs
*.aiff lfs
*.aif lfs
*.mod lfs
*.it lfs
*.s3m lfs
*.xm lfs
# Video
*.mov lfs
*.avi lfs
*.asf lfs
*.mpg lfs
*.mpeg lfs
*.mp4 lfs
*.flv lfs
*.ogv lfs
*.wmv lfs
# 3D
*.fbx lfs
*.obj lfs
*.max lfs
*.blend lfs
*.blender lfs
*.dae lfs
*.mb lfs
*.ma lfs
*.3ds lfs
*.dfx lfs
*.c4d lfs
*.lwo lfs
*.lwo2 lfs
*.abc lfs
*.3dm lfs
*.bin lfs
*.glb lfs
# Executables
*.exe lfs
*.dll lfs
*.so lfs
*.pdb lfs
*.mdb lfs
# Packaging
*.zip lfs
*.7z lfs
*.gz lfs
*.rar lfs
*.tar lfs
... append to end of your own git config
# First, set your default merge tool to something else, i'm using Sublime Merge
[merge]
tool = smerge
# Don't create backup .orig files while merging
[mergetool]
keepBackup = false
# Setup a profile for UnityYAMLMerge
[mergetool "unity"]
trustExitCode = false
cmd = '/Applications/Unity/Unity.app/Contents/Tools/UnityYAMLMerge' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
#
# Created from the github reccomended Unity.gitignore and the default ignore for Unity Collaborate.
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
# OS Generated
.DS_Store
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
[Tt]humbs.db
[Dd]esktop.ini
# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/
# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta
# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*
# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*
# Visual Studio cache directory
.vs/
.vsconfig
# Gradle cache directory
.gradle/
# Autogenerated VS/MD/Consulo solution and project files
[Ee]xported[Oo]bj/
.consulo/
.vscode/
*.userprefs
*.csproj
*.pidb
*.suo
*.sln
*.user
*.unityproj
*.booproj
*.tmp
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Unity3D generated file on crash reports
sysinfo.txt
*.stackdump
# Builds
*.apk
*.aab
*.unitypackage
# Crashlytics generated file
crashlytics-build.properties
# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*

Requires having Git and Git LFS installed. These instructions were written and tested on mac.

If you are cloning a repo that is already setup, skip straight to the .gitconfig step, everything else should be done for you.

Init the repo

If you are creating a repo, cd into the folder in terminal and run git init then git lfs install to setup git and enable lfs.

Adding gitignore and gitattributes

Create a .gitignore and .gitattributes file by coping the ones above. Add all the remaining files to the repo to be tracked by Git.

Setup .gitconfig to resolve conflics with UnityYAMLMerge

This step only has to be done once per machine.

To resolve conflics in unity's .scene and .prefab files you will need to use unity's custom merge toool, UnityYAMLMerge.

Add the configuration above to your user .gitconfig file located at ~/.gitconfig. This sets up 'unityyamlmerge' as a tool availble to git, but doesn't enable it by default.

Resolving conflics

If you get a conflict in the repo, cd into the folder in terminal and type git mergetool --tool=unity

@thomashope
Copy link
Author

On Windows the path for Unity's merge tool will be something like cmd = 'C:\\Program Files\\Unity\\Hub\\Editor\\2020.3.18f1\\Editor\\Data\\Tools\\UnityYAMLMerge.exe' merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"

You can find the location on your machine using 'Everything' to search for it.

@thomashope
Copy link
Author

thomashope commented Jan 19, 2022

Potential to improve the merge setup using the info here https://hextantstudios.com/unity-using-git/

Also see comments where I asked the author a question and they answered.

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