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

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

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

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

Initial Branch Setup Screen

Confirming Installation Works

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!

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

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

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