Setting up Git for Unity

Stephen York
3 min readMar 16, 2021

Hello there!

So the first thing to do when creating a new Unity project is to set up a git repo to go with it. But fret not, it is quite simple to do.

Step 1: Download git

If you do not already have git installed on your computer, then it is the first thing that you need to do. Open up your favorite browser and simply search git download. Make sure that site you go to is git-scm.com. The should see this:

If not, you are probably on the wrong site and you should double check to make sure that you are on git-scm.com. But if you do see it, then just download the correct version for your computer.

Upon installation, you will be presented with multiple options. Just stick with the defaults, it will be fine.

Step 2: Create git repository

Navigate to github and create an account if need to. Once you have an account, go to your profile by clicking the dropdown arrow in the top right and selecting “Your profile”. Then click on the repositories tap that is next to the overview tap and then click the green button that says “New”.

You should be taken to this page:

From here, give your repo an appropriate name that relates to your Unity project and make sure that you select the add gitignore checkbox. It will give you some options, just type in Unity and make sure that you select it. Now click “Create repository”.

Well done! Your repo has now been created.

Step 3: Linking git to Unity

Alright, last step.

Your repo should be open from the creation process. If not, open it now by clicking on it. Head on over to the code button and copy the link that it displays once you click it. It will look like: https://github.com/Profile Name/Repo Name.git.

Then open up your file explorer and navigate to the folder of your Unity project. Right click it and select git bash here. That will open up the git for that specific location.

Step 4: Initial commits

Just kidding, this is the last step.

Now all that you will need to do is run some git commands.

The first will be ‘git init’ which will initialize the git repo at the folder’s location. Then it will be ‘git add remote origin ‘link’’ where link is, you guessed it, the link that you copied in the last step. You know, this one: https://github.com/Profile Name/Repo Name.git.

Now after that, I always like running the command ‘git remote origin -v’ just as a way to check if everything is working. If you run that command you should get two results: one says “fetch” and the other, “push”. If you do not get anything, then you will want to recheck what you have done to make sure everything is correct.

The next command to run is ‘git pull origin main’ which will pull the repository information into your project. Then simply run ‘git add .’ which will stage everything in your Unity project to be committed.

Almost there! Two commands left.

Second to last last, ‘git commit -m”Message”’ where Message is a relevant message. Since this is the first commit, something like “Initial commit” works well. And last but not least, ‘git push origin main’ will put your Unity project into your git repo.

And there you go! Your Unity project is now linked to a git repo and you are good to go to start that Unity development. Just remember to make frequent commits to your git repo.

Happy developing!

--

--

Stephen York

An Atlanta based Unity developer, who enjoys running, reading, and creating videogames!