Using Git with Game Development

Using Git with Game Development

Source control can be daunting but it is pretty important for sharing with others and backing up to prevent data loss. Sharing projects during game jams are a lot easier to do with source control. We will cover installing git on a windows environment, using online repositories (repos) and getting a Unity game setup with git.

Git and What it Does

Pulled from the site, “Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.” There are other version control systems like subversion but Git is the most popular and widespread.

Online Git Projects

You will want a place to push your projects to so check out these online resources.

Github

The most popular online git management website. There are a lot of open source projects hosted here and a good place to collaborate with others.

  • Free public repos.
  • Limited private repos.

Gitlab

Gitlab has many of the same features of Github.

  • Free public repos.
  • Easy to manage private organizations and repos.
  • Lots of CI/CD tooling.

Others

  • Bitbucket Part of the Atlassian suite.
  • Gitea Light and can be self hosted.

Setup and Visual Git Editors

For windows, we can grab the download right from the git website. https://git-scm.com/download/win

Following the instructions, it will setup defaults and access to git from the command line. This is the usual way to use git, but we will cover visual editors for commiting and pushing to remote repos. Once the install is done, you should be able to open the command line or powershell and type in git --version and get something like git version 2.19.0.windows.1. There is a lot of documentation so if you plan on using the command line, read up.

Visual editors

Visual Editors for git makes source control a lot easier. You may need to revert to the command line every once in a while to fix things, but for the most part visual GUIs work well.

GitKraken

Our example editor for walking through using git. It has a lot of features is usually fast. The free version limits you to one account email and name versus the pro version. Profiles are handy so you can commit with your personal or work email. It has a yearly subscription for the pro features, so keep that in mind if you plan on using it professionally.

gitkraken

SourceTree

SourceTree handles git projects well and is free. Also by Atlassian, it integrates well with BitBucket. It has had issues with large git projects in the past.

source tree

Sublime Merge

Sublime Merge is new as of October 2018 and is very good. It’s free to try and then a flat $99 for a perpetual license. One downside is it only shows changed files in a flat list at the moment, so be careful when changing to many files in one go.

Super fast and powerful. Check it out if you use or like Sublime Text.

sublime merge

Github Desktop

Provided by Github, a simpler visual git editor.

github desktop

Unity Project Setup

We are starting with these assumptions.

  • You have a Github account
  • You have a version of Unity installed.
  • You have git installed. We will be using Gitkraken with Github connected.

We will setup projects two ways. Repo first or existing Unity project first.

 

1. New Unity Project and Repo

To start, we are going to create an empty Github project. On the top right of the page there should be a plus button where you can hit new repository.

new repo setup

Once you have the project setup in github, clone in using your git tool. Here, in GitKraken, we have Github connected so it can list your projects and ask you where to download it to.

repo clone

repo clone github

Once it’s ready, it may ask you to initialize the repo. This happens if you did not setup a readme file on github. Go ahead and do it.

Next up, we are going to create a unity project in the repo. Go ahead and select the folder to create it in.

new unity project

This will create the unity project one folder level in the git repo folder. In order to have it at the same level as the git repo, you will need to setup the unity project before connecting to the github remote.

Now, before we commit these files, we need to add a .gitignore. There are a lot of extra files unity uses that clog up our repo and makes downloading it slow. Head over to this page and create a .gitignore file in the unity project folder.

Before

repo changes count

After

repo changes count after .gitignore

Now that we have the files we want, we need to commit our changes and push to the remote.

unity commit gif

git commit --message Basic unity setup.

unity push gif

git push

Now that you pushed your code, your repo should look something like this.

unity repo push complete

Now that you have source control remember to commit and push often!

2. Existing Unity Project

It is mostly the same if you are just starting with source control and have an existing project.

Take your existing unity project and open up GitKraken. We will need to init the git project. There are ways to setup the remote while initializing but we will add the remote ourselves.

unity repo push complete

Go ahead and add the Unity .gitignore provided in the drop down or head over to this page and create a .gitignore file in the unity project folder.

With your .gitignore, your changed files should look like this and not include folders like Library or Temp.

repo changes count after .gitignore

Commit.

unity commit gif

And now to setup the remote.

We are going to create an empty Github project. There should be a plus button where you can hit new repository on the top right of the Github page.

new repo setup

Do not check the initialize repo with readme. You will have to force push overwriting that content.

Now you should have an empty git repo online. Grab the git url. For example, is https://github.com/judah4/unity-game-project2.git. On the left of Gitkraken, there is a remote list. Press the + and add the new Github remote.

repo changes count after .gitignore

It may ask you to authenticate with Github. This page should help with connecting. https://support.gitkraken.com/integrations/github/

Now that you have a remote, push and share with others!

unity push gif

There are multiple ways to do all these things and with projects using other engines like Unreal. Hopefully this helps you understand a bit how to save your projects with git and pushing to github.

Other Unity Tips

  • Don’t work on the same scene as other people. They never merge properly.
  • Don’t upgrade unity versions right away for an existing project.
  • Use and abuse the asset store.
  • Enjoy making games!

 

Originally post at https://www.judahperez.com/programming/tutorials/2019/01/21/using-git-with-gamedev.html