When initializing a Git repository for Unity development, there are a couple of things that need to be done.
Not everything should be versioned in the repository. You can add the template below to your .gitignore
file in the root of your repository. Or alternatively, you can check the open source Unity .gitignore on GitHub and alternatively generate one using gitignore.io for unity.
# Unity Generated
[Tt]emp/
[Ll]ibrary/
[Oo]bj/
# Unity3D Generated File On Crash Reports
sysinfo.txt
# Visual Studio / MonoDevelop Generated
ExportedObj/
obj/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
# OS Generated
desktop.ini
.DS_Store
.DS_Store?
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
To learn more about how to setup a .gitignore file, check out here.
By default Unity projects aren't setup to support versioning correctly.
External
option in Unity → Preferences → Packages → Repository
.Visible Meta Files
in Edit → Project Settings → Editor → Version Control Mode
.Force Text
in Edit → Project Settings → Editor → Asset Serialization Mode
.File
menu.One of the few major annoyances one has with using Git with Unity projects is that Git doesn't care about directories and will happily leave empty directories around after removing files from them. Unity will make *.meta
files for these directories and can cause a bit of a battle between team members when Git commits keep adding and removing these meta files.
Add this Git post-merge hook to the /.git/hooks/
folder for repositories with Unity projects in them. After any Git pull/merge, it will look at what files have been removed, check if the directory it existed in is empty, and if so delete it.