Integrating Unity with Github

Jean-Noel Seneque
5 min readApr 26, 2021

--

New to versioning control? This article will teach you the basic concepts and guides you with hands-on exercises to versioning control your very first project.

After completing this series, you’ll be able to:

  • Understand the benefits of version control
  • Explain version control concepts such as PULL, ADD, COMMIT, PUSH, BRANCH, REVERT, and RESET.

Download and Install Git

Firstly, we need to download Git. Go to https://git-scm.com/

Now click either the Windows or Mac build to start the download.

Git Home Page

Click on the downloaded file to launch it.

With the Git install window ready, leave the default settings and click on the Next button on each of the windows and install the application.

Close the Read Me file if it appears.

Create a new Unity Project

I recommend creating a new Unity project so you may follow along, once you have done that, remember the location so we can navigate there soon.

Setting up a new repository on Github

If this is your first time using Github, sign up. Once you are in Github, create a new repository.

On the Create a new repository page, give the repository a name. I called mine Version Control.

You may give the repository a description.

Leave the scope as Public.

Public: Anyone on the Internet can see this repository but you decide who can commit (change) to it

Private: You choose who can see and commit to this repository

Under the Initialize this repository with section, check Add .gitignore

This provides Github with a list of files and folders in Unity that it can ignore and not bother version control.

Click on the dropdown that appears and in the Filter ignores… type unity

Select Unity

Click on the Create repository button

You should in your newly created repository with it’s first commit of the .gitignore file

Launching Git and our first commit

The first golden rule in versioning control, mostly when working in a team environment is:

PULL — COMMIT — PUSH

We PULL to get the latest changes, COMMIT our changes locally, then PUSH our local version to the Github repository.

Locally? Basically, you have a copy of the project locally and can make changes to it. Once you are happy, you commit those changes and then push it to the server so everyone else has access to it.

Let’s give this a go, first, we need to link Github to our local project. Back on the Github Version Control repository,

Click on the Code button and copy the URL. You can either select the URL or click on the clipboard icon.

Now, navigate to the Unity project that you created earlier. Either via Windows Explorer or right-click inside the Project Window in Unity and select Show in Explorer.

Right-click in Window Explorer and select Git Bash. This will launch Git Bash with it pointing to the Unity folder that will contain the files we want to be version control.

Now in the Git Bash window, type git init and press Enter.

This is initialise a git repository in the Unity folder locally. Now we are going to link our local repository to the Github server, also known as ‘origin’

In Git Bash window, type git remote add origin . Please put a space after origin. Now right-click the Git Bash window and select Paste. This will paste the address of the project and press Enter.

To verify that our local has reference to the server, we can check this by typing in Git Bash, git remote -v and press Enter

You should see the fetch and push options available to us.

Now, remember back to our gold rule, PULL-COMMIT-PUSH. We are now going to PULL any changes from the server’s repository to our local repository.

In the Git Bash window, type git pull origin main and press Enter.

Now we want to commit our Unity project and to do so we need to mark the files we want to commit. To identify the changes since our last commit (this is our first), we need to type git status and press Enter.

You should see that the Assets, Packages, and ProjectSettings folders need to the committed. You could go ahead and commit each and every folder and file using git add [individual file], but the easiest and quickest is to type git add . (that is the period key) and press Enter to commit ALL.

Now if you were to type git status and press Enter, you will see a list of files ready to be committed.

We are now ready to commit our files to the repository locally.

Type git commit -m “Create new unity project” and press Enter.

Now remember this is all happening in our local repository, we now need to PUSH these changes to the server.

Type git push origin main and press Enter

Now go to your Github website, you will see that your first commit has been pushed to the server’s repository successfully, well done!

If you enjoyed reading this article, click on the Follow so you may be updated on my next one.

--

--

Jean-Noel Seneque
Jean-Noel Seneque

Written by Jean-Noel Seneque

A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity www.jeannoelseneque.com

No responses yet