Version Control is an important thing when you’re working on projects with several different people involved. One could argue that it’s important even if you’re working by yourself since you can maintain consistent backups of your projects. Throughout the years, Unity3D has had several different “built-in” version control solutions. One of the best ones, in my opinion, was the Unity Asset Server. Unfortunately, the Asset Server is now a legacy product and it sounds like Unity will no longer be updating it for future releases. The other downside to the Asset Server is that it requires a Pro license for Unity in order to implement it. Aside from the Asset Server, there are several different third-party solutions such as PlasticSCM, Perforce, and UVC. I’ve experimented with all of these different solutions and the best one that I came across was none other than simply using GitHub. In this post, I will detail the steps that need to be taken in order to get your Unity project’s version control working with GitHub.
Setting up GitHub and Unity
The first thing that you will need to do is create a GitHub account.
- Go here
- Fill out all the information on the page and “Create Account”
- Choose a plan that you want to use. You can use the free or paid account to accomplish version control with Unity. The main benefit of a paid account is the ability to set your repository to private. If you use a free account, your repo will be public and other people can see it.
- Once the account is made, go to your dashboard
On your dashboard, click the “+ New Repository” option:
- On the New Repository window, select the owner of the repo (this will probably just be you)
- Put in a repository name. E.G: MyUnityGame.
- Put in a Description if you want.
- Set it to public or private (If you’re on a free account you can only choose public).
- Check the box that says “Initialize this repository with a README”
- Click the “Add .gitignore” box. On the filter box that comes up, type “Unity”. You will see a Unity option come up in the list, choose this option.
- You can leave the “Add a license” box alone unless you know what kind of license you want to use. I usually leave mine blank.
- Click “Create Repository”
Now that the repository is created, you need to get the repository onto your computer. To do this, download and install GitHub Desktop. There are Mac and PC versions of the program.
Once GitHub Desktop is installed, open it up and sign in to your GitHub account when it asks you for your credentials. If you ever need to login to your account again for any reason (such as a password change), click the Gear Icon in the top right of the program and choose “Options”, as seen here:
Then choose the “Add Account” button:
On the main GitHub Desktop Window, click the “+” Icon at the top left of the program. Choose the “Clone” option on the window that comes up. Here, you will see a list of repositories that you have available to you. Left-click on the one you want and choose “Clone repository” where repository is the name of the repository you are looking to clone. When you click this, GitHub will ask you where to save the clone. Choose a location on your hard drive that works best for you and it will begin copying the repository to your local machine.
Once the transfer is done, you should be able to see your repository on your local machine, in the folder that you told it to clone to. E.G: C:\Users\Documents\MyUnityRepo
At this point, you can either create a new Unity project inside of this folder or you can transfer an existing project into this folder as seen here:
Before you start to commit or pull changes from GitHub, you need to make sure your Unity is setup properly. Open up the Unity Project that you want to setup for use with GitHub and go to Edit à Project Settings → Editor
On the right side of Unity, where the Inspector usually is, you will see a bunch of settings listed. From the “Version Control” drop down box, choose “Visible Meta Files”. From the “Asset Serialization” drop down, choose “Force Text”. See the following screenshot:
It is important that this is done. If you do not do this, your GitHub commits and pulls will NOT work.
Once this step is done, you can begin to commit and pull changes to your GitHub repository and everything should work.
The .gitignore file that comes with the Unity GitHub .gitignore preset passes over just about every file and folder EXCEPT for the Assets and ProjectSettings folders from your Unity Project. This means that whenever a change is pulled from the repository, Unity will have to build a library file for it on your machine. Depending on the volume of changes, this may take a while or it may take a few seconds. This also means that if you make changes to your Unity interface on YOUR computer, those changes will NOT be committed to the repository and to everyone else’s computer. Basically, your Unity UI is unique to your computer so you can setup your UI however you want and the other people on your project will not have their own Unity UI changed.
That’s about all there is to setting up Unity with Github as a Version Control solution. If you’re not familiar with GitHub or how Git works, you will want to research that information since this post does not cover the ins and outs of Git.
Blogger: Mark Philipp, Application Engineer at Studica
Share this Post