Page 1 of 1

Using Git With Unity

PostPosted: Wed Oct 23, 2013 10:08 pm
by BenChang
Hosting Services

http://github.com
http://bitbucket.com

Git Clients

Command line client:
http://git-scm.com/downloads

SourceTree (Win, OSX)

http://www.sourcetreeapp.com/

Tower (OSX)
http://www.git-tower.com/

Git Command Cheat Sheet

http://www.git-tower.com/blog/git-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 github.com 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 README
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 "https://github.com/username/repositoryname.git". Use that with the "git remote add origin" command:

Code: Select all
git remote add origin https://github.com/benchang02/unitygitdemo.git


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 https://github.com/benchang02/unitygitdemo.git


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