Unity 5 and Git

Sooner or later I'll have to face with this topic: how to use Unity with your preferred Source Versioning System.
In this post I'll show how to use Unity 5 with Git.




Prepare Git

Create a git repo on-line (eg. bitbucket.com, you can create a private repository)
Suppouse the repo name is <REPOSITORY>
Suppouse the git user is <USER>

Prepare Unity 5

Save your Unity project on your local filesystem (e.g. "/path/to/your/project")
Switch to "Visible Meta Files" in Edit → Project Settings → Editor → Version Control Mode
Switch to "Force Text" in Edit → Project Settings → Editor → Asset Serialization Mode
Save scene and project from File menu
Quit Unity
Delete the "Library", "Temp" and "obj" directories in the project

Init Git

Open Console (dos or shell)

cd "/path/to/your/project"
git init
git remote add origin https://&lt;USER&gt;@bitbucket.org/&lt;USER&gt;/&lt;REPOSITORY&gt;.git
git add *
git commit -m "First commit"
git push -u origin master

Set the .gitignore file

create a ".gitignore" file with this content
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
UnityGenerated/
Assets/AssetStoreTools*

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

# Unity3D generated meta files
*.pidb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# OS generated
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
</pre>
Execute following shell commands:
<br />
<pre class="prettyprint">git add -gitignore
git commit -m "git ignore configuration"
git push -u origin master




Done. Then you can manage your Unity project by using these (pretty simple) git commands:
git add * (to add your updated files)
git commit -m "comment" (to commit your file from stage to HEAD)
git push -u origin master (to push your changes to remote repository)
git pull (to fetch remote changes, if any)

Comments