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. I 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.
- Easy to manage private organizations and repos.
- Lots of CI/CD tooling.
Others #
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 I personally use 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 #
I personally use a visual editor. I do have to revert to the commands every once in a while to fix things, but for the most part I use visual GUIs.
Gitkraken #
My preferred git editor. It has a lot of features that I like and 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.
SourceTree #
I haven't used it in a while but SourceTree handles git projects well and is free. Also by Atlassian, it integrates well with BitBucket. My main issue with it is it slows down with larger projects or at least it use to.
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. The only downside for my usage is it does not have a tree view of file changes and instead shows all changes in a flat list. It's not bad if you keep your changes down to a few files, but at this point I'm accustomed to browsing changes by their folder structure.
Super fast and powerful. Check it out if you use or like Sublime Text.
Github Desktop #
Provided by Github, a simpler visual git editor.
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.
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.
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.
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 #
After #
Now that we have the files we want, we need to commit our changes and push to the remote.
git commit --message Basic unity setup.
git push
Now that you pushed your code, your repo should look something like this.
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.
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
.
Commit.
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.
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. Mine, 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.
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!
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!
If you want to support me and trying out Gitkraken, join through my referral link. https://www.gitkraken.com/invite/3pkBJSRn
- Previous: Top 5 Games 2018
- Next: Make it Work, Make it Right, Make it Fast