How to effectively use Git with Unity when working between Windows and MacOS

Hello all,

This is my situation:
My main workstation is a Windows computer, but I also use a MacBook Pro when on the go.

So far I have this set up:
global gitignores on both devices so that I’m not moving over any OS specific files between computers since they are different operating systems.

local gitignore that I’ve added to the root of the game project directory. This is the gitignore that I used: gitignore/Unity.gitignore at main · github/gitignore · GitHub

local gitattributes that I’ve added to the root of the game project directory for LFS that I got from here: .gitattributes for Unity3D with git-lfs · GitHub

setup UnityYAMLMerge using this Unity article: Unity - Manual: Smart merge

UnityYAMLMerge is currently where I’m having issues. If you open the link you will see that there is a specific path for both MacOS and Windows for YAMLMerge. The config file found in the .git folder currently has the git setup with the windows path but how would I be able to do it so that it uses the path dependent on the OS. When I pull this project into my Mac, the UnityYAMLMerge is still going to have the Windows path which won’t work with MacOS. How would I be able to get this to work on both computers?

The actual location of the UnityYAMLMerge executable shouldn’t be part of your project. It’s part of your user’s git config for the machine (~/.gitconfig). So on windows if would be “C:\Users<username>.gitconfig” and on mac it would be "/Users//.gitconfig.

In your project itself you should just have entries that refer to the merge tool by name “unityyamlmerge”. Git will then use the mapping from your “~/.gitconfig” file to figure out where the merge tool actually is. For example in my project I use a .gitattributes file with entries like this:

*.mat merge=unityyamlmerge eol=lf
*.anim merge=unityyamlmerge eol=lf
*.unity merge=unityyamlmerge eol=lf
*.prefab merge=unityyamlmerge eol=lf
*.physicsMaterial2D merge=unityyamlmerge eol=lf
*.physicMaterial merge=unityyamlmerge eol=lf
*.asset merge=unityyamlmerge eol=lf
*.meta merge=unityyamlmerge eol=lf
*.controller merge=unityyamlmerge eol=lf

My bigger problem working between the two has always been line endings :frowning:

Thank you! I had it written in the wrong file then. That makes sense since each computer has its own gitconfig.

For line endings, wouldn’t this be helpful:

[core]
autocrlf = false
[filter “lfs”]
required = true
clean = git-lfs clean – %f
smudge = git-lfs smudge – %f
process = git-lfs filter-process

1 Like