Unity Dev: Git Gud

Alex Somerville
6 min readMar 16, 2021

Making a great game takes a village… and sometimes a lot more than that. Collaboration is of the utmost importance. To do this, we rely on one of the most important aspects of any software development. Version control. The concept of version control allows many people to participate in a project at the same time and maintain a clean and recoverable code base. When it comes to version control, there’s only one place to go… Git.

Installing Git

Head on over to https://git-scm.com/downloads, download, and install the latest version for your operating system.

For Windows, this will install the Git Bash application which will allow you to run git commands in its console. Depending on your OS, there are a few third party consoles out there that you may enjoy using more. On Windows, I use CMDer. On OSX, I use iTerm2. Installing Git will allow you to use it in these shells respectively upon opening a new tab or restarting the application after it’s done installing.

Using Git

Before getting into the basics of Git, there’s a couple handy links to help you on your way with using Git for your projects.

GitHub Cheatsheet: GitHub, a popular repository for your git enabled projects, has created a great quick reference sheet you can print out or refer to when you’re struggling to remember which commands do what.

Git Documentation: As always, the original documentation is a great place to learn about the tool you’re using. It might seem overwhelming at first glance, but it’s broken down into an easy reference system to help you find the information you need.

Gittin’ Around

Navigating the console

The first thing you need to do is navigate to the folder you’re using for your Unity project. When you open your terminal, you’ll be defaulted inside of your Users folder. From there, we use the cd command to get around relative to where you currently are. For example, I keep all my Unity Projects in a folder aptly named “UnityProjects” directly inside of my Users folder in Windows. So to get inside that folder in my terminal after opening a new tab:

cd UnityProjects/

If I was elsewhere, I could include the full path to get to my folder quickly, like so:

cd C:\Users\jalex\UnityProjects

You can use also cd .. to go back a level if you wound up in the wrong spot.

GitHub

If you haven’t already, go make yourself an account on Github.com and start a new repository. Give it a name that’s descriptive of what the repository is going to contain… like the name of your game. Additionally, have git generate at least the recommended Unity .gitignore file for your repository. This will help prevent certain files from being included in the version control that don’t necessarily need to be there.

Adding a README file will allow you a convenient spot to provide a description including important notes or updates about your project that need to be taken into account by other participants in the project.

Creating a new repo with GitHub

GitHub & Your Computer: Playing Nicely

You’re going to want to follow the instructions at https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account. This will provide step by step instructions to allow your computer to communicate with your GitHub account and not run into permission errors.

Connecting Your Local Repo to GitHub

Initialize your local git repo by running git init while inside of your project folder.

Inside of your GitHub project repo, you’ll see the “Code” button on the top right of the project view. Drop this down and copy the URL from the HTTPS tab.

Back in your terminal window, we’ll run git remote add origin {{Your GitHub HTTPS URL here}}

To break this down a bit, let’s look at the command we just used:

git remote : This refers to the git command and is stating that we’re going to be configuring the remote repository (the instance of the project that’s going to live on GitHub)

add : We want to add a reference to a remote repo to our local repo.

https : This URL is the pointer, letting our local repo know exactly where our remote repo lives.

To ensure we’ve got our remote setup properly, run git remote -v which will list out the remote repositories we’ve added to our local. For now, we’re keeping it simple because we only really need one repo for our personal game project.

Congratulations! You’ve now successfully created a version controlled Unity project. A couple house keeping items to keep things simple follow here:

Your first pull: git pull origin main

Establish tracking for your branch: git branch --set-upstream-to=origin/main main

You can now use a simple git pull to retrieve new updates that are on your “main” branch. It’s always good practice when collaborating on projects with others that you do a git pull as the first thing you do before sitting down to work on something so that you have the latest code and assets!

Adding, Committing, and Pushing

Since we added our remote repo to an already established local Unity project, if we run git status we can see that there’s already files ready to commit! The output shown below are the parents directories ready to be staged for a commit to our remote. There are other directories in there, but they’ve been filtered out by our auto generated .gitignore file that we just pulled down from our remote.

Adding: Let’s get these files ready to add to our remote repo with a simple git add .

Once that command is done running, we can use git status to see each and every file that’s ready to be committed and pushed to our remote.

Committing: Alright, you’ve reviewed the files ready to be pushed up and are happy with it. Let’s commit these files with a simple message, like so:

git commit -m "Initial Commit"

commit tells git that we’re ready to commit to these files, changes, and/or deletions.

-m is a flag, telling git that we’d like to add a message to our commit. This is a great place to let your collaborators know what you were working on with this particular commit.

"Initial Commit" is the message we’re including that will get shown along with the changeset associated with this particular commit and help everyone to understand exactly what happened with this commit.

P-P-P-Push it real good! Almost there! Our last step is to push this commit up to our remote repo so that others can pull the changes and work with your improvements on their own local systems.

git push is all you need here.

You’re done! Remember to refer to Git and Github’s own documentation if you run into problems. For now though, savour your first commit. You just made a hell of a first step toward making your first game.

--

--

Alex Somerville

On a quest to become a game developer. Still sometimes providing unsolicited advice about how to function in society.