How to setup Git for a Unity project

4 March 2022

First of all, why use a version control system (VCS)? 🤔

This is only a quick overview of the reasoning, but nonetheless, I strongly suggest you use some sort of version control, even if you work alone.

But Git is only one of the many version control systems, so why Git?

Now, I personally used Git in most professional projects I worked on, but that's not a reason to discourage you of using other systems. There are definitely valid reasons to do so and I invite you to learn about the differences between these systems.

But if you want to use Git with your Unity project, it is very simple to do. Here are the steps (for Windows):

Step 1: Install Git

Install Git here:

Choose the standalone installer. Select either 32 or 64 bits depending on your computer. Chances are that your computer is 64 bit, there is not a lot of 32 bits computer left nowadays.

Double click on the downloaded .exe file.

You should now see this:

Keep the default options and click next until you see the install button.

Click on install.

Congratulations, Git is now installed on your computer!

Step 2: Create a remote Git server

If you want to share your files (code or images or .fbx or whatever), a common way of doing this is by using a central server. Theoretically, this is optional, you can choose to use a decentralized server-less workflow. But a lot of people, myself included, use a server as the main source. 

For their server, most people use services such as GitHub, GitLab, Bitbucket etc...

I personally like GitLab because it offers you a lot of storage for free and I just find the menus and options are well thought out. I'll continue this example with GitLab but you can use any service you want.

If you don't already have an account, you can create one here: 

Sign into your account.

Create a new project.

Click on "Create blank project".

This project is called a Git "repository". It's a project where you can put files. Think of it like a folder on your computer. But a special Git folder. In this folder, we will put our Unity project, but we could put anything we want.

Enter the info about the Git repository you want to create. Make sure the "Initialize repository with a README" checkbox is checked.  Click on "Create project"

You should now see something like this:

Step 3: Connect to the remote Git server

Now that the repository is created on the server, we need to inform Git on our computer about this server.

One way to do that is to click on the blue "Clone" button.

Copy the shown URL under "Clone with HTTPS".

Go on your computer and open the file explorer.

Navigate to where you want to put your future Unity project. Do not create a folder, Git will do that for you.

Do a right click in the explorer while holding the shift key.

Click on “Open in Windows Terminal” or “Open PowerShell window here”.

Type git clone in the terminal and then paste the URL you copied from GitLab. It should look like this:
(although maybe not with words in French 😄)

Press the enter key.

Enter your GitLab username and password

Git is now creating a folder for your repository, named after your repository, and downloading what is currently in your repository. If you left the default settings in GitLab, it should only have downloaded a file.

Tell Git how to label your work by typing into the terminal:

git config --global "The name you want to use"

Close the Windows PowerShell window.

You now have a Git repository on your computer, and it is securely linked with a Git server online! 💪

Step 4: Unity setup

Unity improved a lot the compatibility of their default settings with Git in the recent years so there is not much to do to add a Unity project to your Git repository.

If you do not have Unity yet, you can download it here: 

Install Unity.

Open the Unity Hub.

Click on "New project".

Specify the location where you want to create the Unity project (the location of your Git repository).

Click on "Create project".

And that's it! You now have a Unity project that is also considered a Git project. 🎉

Step 5: Configure Git

Without going too deep into specifics, I recommend that you add a ".gitignore" file into your repository.

A ".gitignore" is a configuration file to tell Git which files to ignore. Unity generates lots of files on your computer that are not useful to send to your colleagues because the Unity on their computer can regenerate them itself. So, it's best to not send them on the server to save space, time and avoid Git conflicts. 😬

You can write you own gitignore or use the gitignore I mentionned here.

Take the file and put it at the root of your Unity project like this:

Restart your computer.

And you're done! You can now start creating with Unity and Git. 😀

Wait, but how do I use Git?

That's a good question, but it's worth a whole tutorial by itself. Some developers have been using Git for more than 10 years and still don't master it. So let's say there is a lot to learn about Git. If you want to dig into it, you can always read the excellent and free Pro Git book:

You can of course use Git with the command line. You can also use clients (external user interfaces) like SourceTree or Git Extensions.

If you find them too complicated, I must agree with you. That's why I created Crafty: A plugin for Unity that enables you to easily use Git without having to learn all about it.

I would love for you to try it, after all, you are now all set up!