More than one way to skin a cat

Workflows for using git with Unity Projects

Christopher West
5 min readMar 17, 2021
Photo by Arnold Francisca on Unsplash

As in most things in programming, there is more than one workflow for setting up your Unity project to work with git. We’ll go over two of those workflows that I have used:

  1. Using the command line interface that comes with git
  2. Using a GUI interface for git

Like your choice of git providers, there are several options for a GUI interface to git. These include, but are not limited to, GitKraken, GitHub Desktop, and SourceTree. I am using GitKraken in these examples because it is the option I prefer. Each of these clients has similar functionality and, at the end of the day, they utilize the same CLI commands under the hood.

In both workflows, we create our GitHub repository, and our Unity project, initialize a local repo where our Unity Project is, attach the GitHub repo as a remote and push our local changes to the GitHub server.

GitHub Account

Make sure you already have signed up for an account with your git provider of choice. There are several git providers out there including, but not limited to, GitHub, BitBucket, and GitLab. For our example, we’ll be using GitHub as that is what is used in my course work and it seems to be the most popular of the options available.

Workflow #1: Using Command Line

I’ll go over the workflow using the plain command-line approach first.

Create GitHub Repository

  1. Navigate to https://www.github.com and login if neccessary
  • Click on the “New” button on the left side menu bar next to the word Repositories
  • Alternatively, You can select “Your Repositories” from the profile dropdown menu in the upper right-hand corner of the GitHub interface and then select the “New” button at the top of the Repository list on the displayed page.
  1. Fill out the repository name
  2. (optional)You can give the repository a description to clarify what the repository contains
  3. Select to make the repository Public or Private. Public repositories can be seen by anyone. Private repositories can only be seen by yourself and the people you invite to see the repository.
  4. (optional) I recommend creating a completely blank repo by not checking these optional options and adding these when we set up the local repo. You can choose to add a readme file Which can be useful for others when they visit the repository. The readme file can contain instructions on how to use the code in the repository, links to documentation, descriptions of features, and more.
  5. (optional) I recommend creating a completely blank repo by not checking these optional options and adding these when we set up the local repo. You can choose to add a .gitignore file which tells git what files and filetypes it can safely ignore when committing files to the repo. This file is optional at this stage but will be needed for Unity projects and will be covered separately a little later in this article. If you add it in this step you will either end up replacing it with a local copy later or needing to merge it with the files from your initial local project. If you add it here GitHub will give you a dropdown of possible templates for different types of projects. You can search for Unity to get a starter file with some of the most common Unity settings in it.
  6. (optional) I recommend creating a completely blank repo by not checking these optional options and adding these when we set up the local repo. Lastly, you can choose to attach a License. For this article, we will leave this setting alone but it can be useful to define how the project in the repo can be copied, modified, shared, or distributed. Again, GitHub will suggest some starter templates for you to choose from if you opt to select this option
  7. Click the “Create Repository” button

Create Unity Project

  1. Now you want to open Unity Hub
  2. Click on New
  3. Select your project type
  4. Give your project a name
  5. Enter a path to the location where you would like your project to reside on disk. Take note of the location you choose as you will need it in later steps.

Make Sure git is Installed

First, make sure that you have installed git for your chosen operating system by downloading the appropriate installer and running it from the git website.

Initialize your local repo

  1. Open your Terminal (MacOS) or git bash termial (Windows)
  2. In your Termnial, Navigate to the folder in which you created your Unity project
  3. In your Termnial, entergit init

Add your .gitignore file

If you have a .gitignore file for Unity you can copy it into your project folder now so that the files that we want to be ignored will already be ignored when we make our commit. If you don’t have a .gitignore file yet you can get one from several sources online. I have included a few below:

Link your GitHub repository to your local repository

In your Terminal, enter the following command and press enter

git remote add origin https://github.com/{username}/{repositoryname}

Add your project to git and make your first commit

  1. In your Termnial, enter the following command and press enter
git add .
  1. In your Termnial, enter the following command and press enter
git commit -m “initial project commit”

Push your commit up to the GitHub repository

  1. In your Termnial, enter the following command and press enter
git push

That’s it! Your Unity project is now stored in both your local and remote repositories and ready for you to dive into development!

Next Time!

Whew! That was quite the journey! Tomorrow, we will look at using GitKraken, a GUI-based git client, to do the same thing we did from the command line in this article. If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.

--

--

Christopher West
Christopher West

Written by Christopher West

Unity Game Developer, Software Engineer, Gamer, Musician, and Father. Christopher is a creative that enjoys a challenge and loves coding.

No responses yet