Unity and Git

I want my repository to only have the project files that Unity needs for the project to load properly and so I can work with it properly. Like, for example, in my Project folder there is the folder ‘Build’. I don’t need that to be able to continue working with the project. I also don’t think I need the ‘Temp’ folder, right?

Well, I created a completely new Unity project to see what is there from the start - the folders ‘Library’, ‘Assets’ and ‘ProjectSettings’. The problem is that the ‘Library’ folder has files that change often and I don’t think the Project really needs them to work (like there’s a metadata and cache subfolder that constantly changes inside of it).

So can you guys give me a tip or two on how to make sure that I only commit files that the project needs and don’t have to commit some useless temp files every time I commit, without actually needing them.

Hey Fabis94 -

  1. Make sure you have metadata enabled (Edit → Project Settings → Editor) and make sure Version Control is set to “Meta Files”

  2. Assuming you have a git repository created, just add the following to your .gitignore file

Unity3D .gitignore file.

Store this file at the root of your local repository.

.DS_Store
Library/AssetImportState
Library/AssetServerCacheV3
Library/FailedAssetImports.txt
Library/ScriptAssemblies
Library/ScriptMapper
Library/assetDatabase3
Library/cache
Library/expandedItems
Library/metadata
Library/previews
Library/guidmapper
Temp
*.csproj
*.pidb
*.sln

Does anyone have a definitive Unity and Git guide?

This post is the third one I’ve seen about Unity and Git and they all have different .gitignore files and say different things.

ex: Account Suspended | Lithium Hosting
and http://raypendergraph.wikidot.com/using-git-with-unity3d
and http://www.chrisdanielson.com/2011/06/04/unity3d-projects-version-control-git/

all say different things!

Unity say http://docs.unity3d.com/Documentation/Manual/ExternalVersionControlSystemSupport.html
“When checking the project into a version control system, you should add the Assets and the ProjectSettings directories to the system. The Library directory should be completely ignored - when using external version control, it’s only a local cache of imported assets.”

For now I’m just using a .gitignore of:

#.gitignore file
Temp/*
Library/*
Build/*

#Un-ignore these specific files

#ignoring pidb, they are just code completion caching data according to:

What are MonoDevelop's .pidb files? - Stack Overflow

*.pidb
*.userprefs

Anyone?

ty!

Here’s a good one for anyone else who comes looking like I was:

http://devblog.phillipspiess.com/2012/06/17/unity-3-5-free-and-source-control-lessons-learned-from-7dfps/

Check this tutorial http://blog.hfarazm.com/git-for-unity-create-projects/

The last two links are dead. Here is the text of those using the wayback machine.

https://web.archive.org/web/20120828170549/http://devblog.phillipspiess.com/2012/06/17/unity-3-5-free-and-source-control-lessons-learned-from-7dfps/#more-312

#This is the git ignore file used in Duck Hunted
#Note that ! negates an ignore. We ignore everything in Library then
#un-ignore the metadata folder and some specific files
#Use at your own risk, this may totally destroy your project, but it worked for us

#NOTE: this will cause your collaborators to re-import assets periodically
Temp/*
Library/*
Build/*
#Un-ignore these specific files
!Library/*.asset
!Library/AssetImportState
!Library/AssetVersioning.db
!Library/BuildPlayer.prefs
!Library/ScriptMapper
!Library/assetservercachev3
!Library/expandedItems
!Library/guidmapper
!Library/unity default resources
!Library/unity editor resources
!Library/metadata/

#ignoring pidb, they are just code completion caching data according to:

What are MonoDevelop's .pidb files? - Stack Overflow

*.pidb
*.userprefs


Other one:

===============

Unity generated

===============

Temp/
Library/

=====================================

Visual Studio / MonoDevelop generated

=====================================

ExportedObj/
obj/
*.svd
.userprefs
/
.csproj
*.pidb
.suo
/
.sln
*.user
*.unityproj
*.booproj

============

OS generated

============

.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

You can use the Unity .gitignore preset from Github.

Since I don’t want to have binary files under version control, I wrote my own backup tool. You can specify which filetypes you want backed up and not under version control in your .gitignore file. The tool then parses your .gitignore file and recursively searches your asset directory to search for files of the specified types. It copies all files, including their metafiles and those of the directories over to another directory and - if you wish - compresses it into a zip archive.
Here’s my .gitignore file:

[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/

# UBB backups
UBB/
unitybinarybackup.exe

# UnityVS
Assets/UnityVS/*
Assets/UnityVS.meta

# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
*.sln
*.suo
*.user
*.userprefs
*.pidb
*.booproj

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Excluded binary files #!UBB!#
*.wav
*.wav.meta
*.ogg
*.ogg.meta
*.mp3
*.mp3.meta
*.tga
*.tga.meta
*.psd
*.psd.meta

This file makes git ignore wav, ogg, mp3, tga and psd files and backs them up using my tool instead.
Since the UBB folder where the backups are created isn’t actually a folder on my machine, but a symlink, all backups are automatically synched with my Google Drive. Quite convenient. :wink: