Wednesday, 25 November 2015

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., 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;;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

# Autogenerated VS/MD solution and project files

# Unity3D generated meta files

# Unity3D Generated File On Crash Reports

# OS generated
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)



Post a Comment