Using Git With Unity

Using Git With Unity

Postby BenChang » Wed Oct 23, 2013 10:08 pm

Hosting Services

Git Clients

Command line client:

SourceTree (Win, OSX)

Tower (OSX)

Git Command Cheat Sheet

Unity Project Setup

1. Create a Unity Project. For this example, we'll call it "unitygitexample"
2. Set it up to use Version Control: Edit->Project Settings->Editor, set Version Control mode to Meta Files
3. Create an empty scene and save it (this is important - Git will ignore empty folders, so you need something in your Assets folder to start off with).

GitHub Setup - Creating the repository

From your account, go to the Repositories tab and click New.
Give it a name. Easiest if it's the same as the name of your Unity Project, but technically it doesn't have to be.
Add a .gitignore for Unity

Connecting the GitHub repository to your local Unity Project

You can use the command line or you can use a GUI client front-end. Here's how to do it from the command line.

1. go into the unitygitexample directory
2. initialize the directory to be tracked by Git:

Code: Select all
git init

3. Connect your local Unity directory to the Remote repository. On your repository's github page, there's a box on the right that has the "HTTPS Clone URL", which will look like "". Use that with the "git remote add origin" command:

Code: Select all
git remote add origin

4. Pull the files from the remote repository to your local directory

Code: Select all
git pull origin master

This will download the files that are currently in your remote repository on github, which to start are just the .gitignore and the README file.

5. Add the files and folders in your local directory. Git maintains a list of files that are tracked. When you add files to your project, you have to also tell Git to track them using the "git add" command; meaning "add to the list of tracked files".

Code: Select all
git add .

This will add the files in your current directory (such as the Assets folder).

6. Commit your changes

Code: Select all
git commit -m "initial commit"

7. Push your changes up to the remote repository

Code: Select all
git push origin master

Other team members: clone the repository

Code: Select all
git clone

This will pull the unity project from the remote repository, giving you a folder called unitygitdemo.

In Unity, open the unitygitdemo folder. Have fun!

Add and commit your changes

In the unitygitdemo folder:

Code: Select all
git add -A
git commit -m "I made the game so much more awesome"
git push origin master

Get the latest updates that other people have pushed

Code: Select all
git pull
User avatar
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest