Setup Git with Unity3d for Commercial Development — Part 1 Installing

While there are other options for working with team members and backing up your Unity3d projects. Git with GitHub is just an industry-standard solution in handling the workflow of sharing game asset files across a team.

So let’s go through the process of getting a project set up using Git, with the intent of working on a commercial Unity3d product.

Why Use Git with Unity3d

Git and the tools around it like GitHub form something called a “Version Control System” which on the simple end helps store every backup you ever make, and just being a controlled way of working with team members.

Now if your solo, maybe just a hobbyist just starting to learn.
You can get away with just any backup system you trust.

Commercial product side, even solo devs get huge benefits with Git. Git can do so much more than just be a backup system. A simple example: Git makes patching a game and distributing the patch to all the storefronts almost automated once set up.

So while Git can be scary at first due to all the new terms, really if you’re capable of working on a video game you’re capable of learning Git.

So Let’s Get Started

First, we need to create a free account on GitHub. Click Here to sign-up and create your unique account. The username will be public to everyone, but your email can be hidden.

GitHub is where we will store the private online copy, and invite any team members to work with us. We can also do other things but that’s all we really need starting out.

Installing Git on your Windows 10 Machine

Now we need to download Git, which is the actual tool we use daily to send files to GitHub. Click Here to go to the below download page, and click the download button on the computer screen for the latest version (at the time of the article that was v2.31.1).

The big button located on the image of a computer screen

It should automatically start downloading else you can click where it says to download manually. This should be an exe with the version number, for example, mine is “Git-2.31.1–64-bit.exe” double click this to start the installation.

With the install, you can almost keep almost all the default options it gives you.

Important Install Setting

As of 2020 Git is in the process of changing the “Default Name” of the first project branch, so we need to ensure we choose a good name. The one Git will default to is “main” so let us just use that. If you use any pre-2020 tutorials or guides in the future just know whenever they say “master” you’ll need to type in “main”.

Initial Branch Setup Screen

Confirming Installation Works

Next up we need to run it! The easiest way is to go to your start menu and type in git, you’ll see a few options pop up but the one we want is “Git Bash”

Opening GitBash will open a console window where you can type. It’ll have your windows10 username and computer name in green.

The $ sign shows where you can type commands in.
So if we type in:

git --version

Like I did below, it’ll show you the version you installed. Doing this is a quick way to make sure it installed correctly before continuing.

Your first Repo!

Repo is a short term for “Repository” which is just a fancy word for “Storage”. The Repo on GitHub is the “Remote Repo” and the one on the computer gets called the “Local Repo”.

So how we start is making the Remote Repo in GitHub. As we need to make sure we have a place to store the project online.

In GitHub no matter where you are on the site there is a little + icon at the top right. Click that and then click “New repository”

Top right in GitHub

From here you get the New Repository page.
Here we can

  • add our Repo name which can just be our Project Name
  • For our example we want this Repo to be Private, not Public
  • We want to add a .gitIgnore with the Unity template. This will ensure it doesn’t upload some system files that Unity generates but we don’t need a backup of.
  • Then we simply click the green “Create Repository” button

Now you’ve got a Remote Repo!

Next Up Creating the Local Repo

Just a reminder “Local” means on your computer.

Quick Note You Need Unity3d Installed From Here On:
I am assuming you have UnityHub and a version of Unity3d already installed. If you need to learn how to install Unity they have a great tutorial on how to install Unity3d here. Go follow that first, then come back.

If you don’t have an existing Unity3d project you want to use with Git, open up UnityHub and create a new project, it can be 2d or 3d. The project doesn’t need to match the GitHub name but it can make things easier to remember.

Next, we need to copy the “Full path” to your Unity Project which is displayed as “Location” when creating the project. In this example, mine is located at “C:\Code\Unity Projects\ProjectName” as I have set up that as my custom location for Unity Projects. You’ll know it’s your Unity Project if you see the project name and the Unity folders like Assets, Library, and Logs.

My custom default location for projects

We need this “Full Path” as GitBash defaults to running commands in our Windows User folder, and we don’t want to run commands there. So we need to open up GitBash and run a command to tell it to move to your project folder. We do this with the command cd which is short for “Change Directory”.

Use my command example below and simply replace my full path with yours. To “Paste” in GitBash you can right-click and click paste (the shortcut is shift+ins). We need to use single-quotations around the full path due to the space in the folder “Unity Projects”

cd 'C:/Code/Unity Projects/ProjectName'

You’ll know it's successful if the yellow ~ turns into your full path (as shown below). Now that we’re in the right spot for our Local Repo, we need to run the ‘init’ command which is short for Initialize. We do this by typing:

git init
Travel to the directory and then git init

We know it successfully initialized if we see (main) at the end.

All we’ve got left is to connect the Local Repo with the Remote Repo. We do this by going to Github and grabbing the HTTPS URL for our project. This HTTPS URL is hidden under the big green code button, and we can just click the clipboard icon to copy the URL over.

Now we simply paste it into GitBash with the git command ‘remote add origin’
Make sure you use your unique URL

git remote add origin https://github.com/marchewitt/ProjectName.git

Then we can type in ‘git remote -v’ as shown below to confirm that it connects

HTTPS URL is hidden under the big Green button
Connecting and seeing that it connected

We’re finally connected! This base setup feels like a lot but now you could repeat this ten times faster with another project.

Next Up

From here we have Git installed and usable. Next, we have to learn the basic commands and day-to-day usage of getting teammate’s code and art, adding our changes, and getting our changes to our teammates.

For that see Part 2 of Setting Up Git with Unity3d for Commerical Development — First Commit

An Austin TX Unity3d Developer with a unique background in marketing, design, & software development leading digital web agencies to success for the past decade