Tools

Version control

Failing Faster involves failing.
Breaking things along the way.
Then doing some damage control.
Or at least Version Control.

Free or cheap
Backup code & assets
Work offline
Easy to use
Console and GUI

Git / Git LFS / SourceTree / Bitbucket

version control

Now you can break everything. And turn back time.
As if nothing ever happened.


What’s Git and who does it work?
How do I install Git on my machine?
Git seems great for code. What about big binary assets?
How do I use Git with Unity?
How do I create the .gitignore file?
How do I edit the .gitattributes file?
How do I create a local Git repository?
How to share versions across several machines?
Why Bitbucket and not GitHub or Git Lab?
Why not just use Unity Collaboration?
How to push the content of your local repository to the remote repository?


What’s Git and who does it work?

Atlassian (I know. Atlassian again) made the best Git tutorial out there. Check it out to understand what version control is and how Git in particular works. Then put it aside and come back to it when you’ll actually start using Git. You’ll see. Super helpful.


How do I install Git on my machine?

Two options.

Option A. Get git. Get comfortable with Git bash and command lines. It’s probably the most efficient way of using Git. Doesn’t seems so, I know. Especially if you’re new to programming. But it’s true.

Option B. Get a nice GUI. It will help by installing everything for you and make things visual. So install Atlassian SourceTree. Told you before. I’m an Atlassian kind of guy.


Git seems great for code. What about big binary assets?

Versioning big files such as textures, meshes, sounds etc. is going to make your Git repository explode. Remember that “versioning” really means storing copies of each file you edit. So if you even have but one 10 Mo texture and edit it 10 times, that’s 100 Mo just for one file (!). And you’ll have many more in your game project.

The solution is Git LFS. Check out Atlassian’s Git tutorial Git LFS section.

It’s a Git extension that basically only downloads the “last” version of certain files. All you need to do is specify which types of files to version like that in a .gitattributes file. We’ll get to that in a sec.


How do I use Git with Unity?

To configure Unity to work with Git I recommend this tutorial by thoughtbot.

What you need to do:

  1. Set Unity Settings for version control to Make Meta files visible and Asset serialization to Force text
  2. Create a .gitignore file
  3. Edit the .gitattributes file

To learn more about this, check out this Git with Unity GDC 2017 talks or this Complete guide to Unity and Git.


How do I create the .gitignore file?

A .gitignore file will specify a list of file types and locations that Git should not version. Things like cache or hidden OS files for example.

To generate the .gitignore file that is right for you head to gitignore.io and specify your game dev stack. Here’s mine created with Unity, Visual Studio Code and  Windows:

.gitignore
# Created by https://www.gitignore.io/api/unity,windows,visualstudiocode

### Unity ###
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*

# Visual Studio 2015 cache directory
/.vs/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb

# Unity3D generated meta files
*.pidb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


# End of https://www.gitignore.io/api/unity,windows,visualstudiocode

At the root of your Unity Project folder create a text file gitignore.txt and past this in. Then open the Terminal where this file is located and rename it to .gitignore using the following command:

ren gitignore.txt .gitignore

Now you can git init. Don’t know what git init means,? You should read this post.


How do I edit the .gitattributes file?

Just like in the .gitignore file, every file type you specify here will be picked up by Git LFS and only pull the last version when requested.

.gitattributes
# 3D models 
*.3dm filter=lfs diff=lfs merge=lfs -text 
*.3ds filter=lfs diff=lfs merge=lfs -text 
*.blend filter=lfs diff=lfs merge=lfs -text 
*.c4d filter=lfs diff=lfs merge=lfs -text 
*.collada filter=lfs diff=lfs merge=lfs -text 
*.dae filter=lfs diff=lfs merge=lfs -text 
*.dxf filter=lfs diff=lfs merge=lfs -text 
*.fbx filter=lfs diff=lfs merge=lfs -text 
*.jas filter=lfs diff=lfs merge=lfs -text 
*.lws filter=lfs diff=lfs merge=lfs -text 
*.lxo filter=lfs diff=lfs merge=lfs -text 
*.ma filter=lfs diff=lfs merge=lfs -text 
*.max filter=lfs diff=lfs merge=lfs -text 
*.mb filter=lfs diff=lfs merge=lfs -text 
*.obj filter=lfs diff=lfs merge=lfs -text 
*.ply filter=lfs diff=lfs merge=lfs -text 
*.skp filter=lfs diff=lfs merge=lfs -text 
*.stl filter=lfs diff=lfs merge=lfs -text 
*.ztl filter=lfs diff=lfs merge=lfs -text 

# Audio 
*.aif filter=lfs diff=lfs merge=lfs -text 
*.aiff filter=lfs diff=lfs merge=lfs -text 
*.it filter=lfs diff=lfs merge=lfs -text 
*.mod filter=lfs diff=lfs merge=lfs -text 
*.mp3 filter=lfs diff=lfs merge=lfs -text 
*.ogg filter=lfs diff=lfs merge=lfs -text 
*.s3m filter=lfs diff=lfs merge=lfs -text 
*.wav filter=lfs diff=lfs merge=lfs -text 
*.xm filter=lfs diff=lfs merge=lfs -text 

# Fonts 
*.otf filter=lfs diff=lfs merge=lfs -text 
*.ttf filter=lfs diff=lfs merge=lfs -text 

# Images 
*.bmp filter=lfs diff=lfs merge=lfs -text 
*.exr filter=lfs diff=lfs merge=lfs -text 
*.gif filter=lfs diff=lfs merge=lfs -text 
*.hdr filter=lfs diff=lfs merge=lfs -text 
*.iff filter=lfs diff=lfs merge=lfs -text 
*.jpeg filter=lfs diff=lfs merge=lfs -text 
*.jpg filter=lfs diff=lfs merge=lfs -text 
*.pict filter=lfs diff=lfs merge=lfs -text 
*.png filter=lfs diff=lfs merge=lfs -text 
*.psd filter=lfs diff=lfs merge=lfs -text 
*.tga filter=lfs diff=lfs merge=lfs -text 
*.tif filter=lfs diff=lfs merge=lfs -text 
*.tiff filter=lfs diff=lfs merge=lfs -text

How do I create a local Git repository?

In SourceTree, select Create and browse to find your Unity project’s folder. Git is going to detect all the files that it’s not currently managing under the “Unstaged files” window.

Click Stage All, enter a description such as “Initial commit” and click Commit.

That’s it really. Now can save and store the current state of any file. And most importantly you can break things without worry. Because you can revert to any version you want. You have control. Version Control.


How to share versions across several machines?

Git will manage a Local Repository only available on your machine.

But what happens if your hard drive explodes? You’ll cry. And have no way to recover. Unless you set up a Remote Repository. Atlassian has you covered. Bitbucket.

Create a Bitbucket account and link it to SourceTree.
In Bitbucket, create a new repo.
Select “I have an existing project” and paste the displayed lines in Git bash (can be opened in SourceTree by clicking the Terminal icon found in the top right corner).

This will reference your Bitbucket online repository as the remote repository for your project. This way you’ll also have a reference for other people on your team to pull from and push their changes to.


Why Bitbucket and not GitHub or Git Lab?

GitHub is great except if you’re looking for free private repositories.
GitLab is good as well and does offer free private repositories.

However, I chose Bitbucket because it integrates perfectly with other Atlassian products I want to use such as SourceTree and Trello. Plus, you can integrate your boards directly into Bitbucket. Neat.


Why not just use Unity Collaboration?

This is probably all you need really. It’s quite straight forward, integrated in Unity, easy to learn. The problem is most professional game developers use a full fledge Version Control. So better learn how to use one. And Git is a safe bet a the moment, really popular, used by 69% of developers according to Stack Overflow’s survey.


How to push the content of your local repository to the remote repository?

With your local repository set up  and the .gitignore file created, you are ready to save the work you’ve done and send it to Bitbucket.
The Git lingo for saving your changes locally is to commit and for sending your changes to the remote repository is to push.

Save your changes in Unity.
Open SourceTree.
Click Stage All to add all the changed files.
Click the Commit icon.
Enter a Description.
Click the Commit button.
Click the Push icon (or tick the Push changes immediately to origin/master before you commit to save this last step.)

Commit small, commit often.
This will help you make sure you don’t lose any work done and can easily revert some changes if something went wrong.

Here is what SourceTree does for you, just as you would have done if you where working with console commands:

Add all changed files to commit
Commit changed files with a description
Push the changes to the remote repository

git add . 
git commit -m "Commit description" 
git push origin master

Now if you bring someone on your team or if you burn your hard drive you can always pull the whole project from the remote repository.


You’re all set. Start changing things, breaking things. Creating things.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.