Setting Up Git for Unity

Adding version control to your projects

Rusben Guzman
4 min readApr 28, 2021

What is git?

Imagine that you are working in your game (or any Unity project) and something went wrong, for some reason you need to go back to a previous state where everything worked in order to continue development.

Git is a version control system, which means that it is a program that allows you to track every file in your project throughout the whole development cycle.

Photo by Joshua Aragon on Unsplash

Some of the benefits Git offers are:

  • Have records of every change on your project
  • You can revert to specific version you need
  • Make collaboration easier, allowing changes in parallel to be merged into one source

Installing git

  • Windows: First download Git here and follow the instruction of the installer wizard.
  • Mac OS:

Install homebrew if you don’t already have it, then open the terminal and type the command below:

$ brew install git

Creating an Unity project

  1. Open Unity Hub (if you don’t have it, download it here and follow the installer instructions)
  2. Select “New”
  3. Select “3D”
  4. Name your project as “GitUnity”
  5. Select “Create” and wait until Unity opens the project

Adding git to your project

  1. Open the terminal (git bash for Windows)
  2. Go to your project directory
  3. Run the command “git init”
git init

The command “git init” creates a Git repository in your project and you will be able to run git commands within it.

First commit

Let’s understand some basic git concepts before making the first commit. When we use with git, we have three areas where the files will be while we are working:

  • Working directory: the project folder on your computer
  • Staging area: Intermediate area between the working directory and the Git repository. In this area you can add files to create a commit (in short a commit is a version of your repository at one point of time).
  • Repository: is a hidden folder that Git uses to track all changes made on your project.

Now knowing the above, let’s see the Git basic commands (note: all git commands start with the word “git”):

  • git status: displays the state of the working directory and the staging area.
git status
  • git add: receive a file/directory name as parameter, and move it from the working directory to the staging area.
git add <directory name>

Tip: you can use the command “git add .” to add all changes to the staging area.

  • git commit: Move changes from the staging area to the repository.
git commit -m “some message that indicates what you did”

Good to go, run the following commands to make your first commit:

  1. git status
  2. git add .
  3. git commit -m “Creating Unity Project”

At the beginning using Git is intimidating but it is really easy and with practice you will become a Git expert in no time.

P.S: Using git is better than making a copy of your files and name it “my_project_final_V2” each time you go to create a backup.

--

--

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.