Github for Unity Tutorial

Github for Unity Tutorial

You do NOT want to experience losing all your codes and hard work due to your hard disk suddenly getting corrupted or any hocus pocus that happens with all IT projects. Source control is very important, so congratulations for managing to find this tutorial on how to use Github for Unity projects. 

Truthfully, it used to be a bitch to use Git with Unity projects. You'll need to set up plenty of .gitignore to make sure Unity file and Git plays along. And also you had to make sure that Git LFS is working as expected or else weird things happen.

With the release of Github for Unity, it's not. a. bitch. anymore to use Git with Unity.

So, let's start.

 

0. Create a new Unity project.

 Yeah, let's try Git with a new Unity project first. You can try it with your current project once you get used to it. Remember to BACK UP if you're using your current/old project anyways. No refunds.

 

1. Download and Install Github for Unity in your project.

 Scoot over to https://unity.github.com/ and download the Unity package.

With your Unity project open, double click on the Unity package and the Github for Unity .unitypackage file will automatically be copied into your project.

 

2. Initialize Github for Unity in your project

 After the previous step, you may or may not see the Github window. If you don't see anything, go to Window > Github. Then the Github window will be added to the same place as the Inspector window. 

Click on the 'Initialize a git repository for your project' button.

You're done! Well, if you don't plan on having a remote repository that is. Which is fine if you don't care if your hard drive get fried.

You may close this tutorial now if you don't plan on making a repo on Github or any other place. Though you should.

 

3. Create a Github repo in Github.com

 Go to Github.com.

Register if you have not.

Create a public repository (private if you don't mind paying).

Done. Your repo should be ready by now.

If you want to keep your source private but you don't want to pay Github for a private repo, you can create a repo at Visual Studio Online (Now Azure DevOps) instead. https://visualstudio.microsoft.com/vso/

 

4. Set your Origin to your Github repo

 Your repo URL will be your origin. For example, my project UnityMobileBase's origin URL will be https://github.com/purrmiaw/unitymobilebase .

(If you're using Azure DevOps, your origin URL will be the URL of the page where you can see your repository)

In your Unity project, in Github window go to the Settings tab. Under Repository Configuration, in the Remote: origin field, fill in your repo URL.

 

5. Commit Changes

 Now, go to the Changes tab. Check all. Fill in your Commit Summary and Description and click Commit to [master]

 

6. Pull from Origin and Push your Repo

 Now, I'd assume you're familiar with Github's terminology. But if you don't, here's a short explanation.

At the top of the Github window, you'll see 4 commands:

 

Fetch: Get all updates from origin without merging your code with origin

Pull: Get all updates from origin and merge your code with origin

Push: Send your updates to origin

Refresh: Refresh the Github window

 

So, now we'll need to synchronize your code with the origin. So what we'll do is do a pull operation, and then push to origin. At the buttons at the top, click 'Pull'. And then click 'Push'.

If you didn't create a readme file when you create the github repo, you will not have any problem. Just pull and push and you'll be done with the tutorial. Your local repo are now synchronized with the origin.

 

6b. If you get the "no common commits" error

 However, if you have created a readme file when you created the Github repo, you will get an error stating "no common commits".

If you encounter this, then we'll need to do a pull and allow unrelated histories first.

To do this, open Windows > Github Command Line. The command prompt will open.

Now, run this command:

 

git pull origin master --allow-unrelated-histories

 

Your local repo will now be updated with the readme file.

Now we've fixed the conflict, simply click on the Push button at the top of the Github window.

Now, you're done! Your Unity project is now under source control with Github.