Unity/GitHub Guide

Linking a Unity project with a GitHub repository using Git Bash

A detailed guide to connect your Unity project with your GitHub repo using Git Bash

Fernando Alcantara Santana

--

So, it’s probable that you’ve been looking for a way to connect your Unity project with a repository on GitHub, in today’s guide I will be explaining, step by step, how can we use Git Bash to provide a connection between GitHub and Unity.

Git Bash is an application that lets you execute, through a command line editor, Git commands in order to control the different versions of a development project like the ones from Unity.

Git Installation

To install it, we need to choose the proper installer according to our operating system into the next site: Git Bash Installer

Once you have the installer, execute it and follow the default installation process
Once you have the installer, execute it and follow the default installation process

After the installation, launch Git Bash and a terminal will be shown to you:

Git Bash terminal
Git Bash terminal

Navigation commands

If you’re not familiar with the navigation commands to reach your system files then you should check these:

  • pwd → This command returns the current path/directory where you’re in the system. The pwd command refers to print working directory.
  • ls → This command returns the list of all the folders and files that can be accessed immediately in the current directory, just like if you were looking at a popular file explorer. The ls command refers to list.
  • cd → This command lets you navigate throughout the folders and disks of your computer. It needs to be executed along with the directory you’re trying to enter. The cd command refers to change directory.
Left image shows change of directory to a disk and right image shows change of directory to a folder
Left image shows change of directory to a disk and right image shows change of directory to a folder

It’s important to know the directory of your Unity project in your file system, as you will need to reach that folder with Git Bash using the above commands.

Navigation to the Unity project folder using the cd command
Navigation to the Unity project folder using the cd command

As an alternative (in Windows file explorer), you can right-click inside the folder of your Unity project and select the Git Bash Here option to open Git Bash inside the directory.

Connect GitHub repo to your Unity project folder

Now, in order to connect our repo we must create one in our GitHub account and decide if it’s going to be public (so everyone can watch what you’re coding) or private (so only people you invite can watch or modify your code).

It’s also important to add a Unity .gitignore to the repo to avoid uploading files that could contain sensitive or excessive amount of content that could make the repo need a lot of space.

Add a Unity .gitignore file before creating the repo
Add a Unity .gitignore file before creating the repo

Then, you should get the url at the right top of your repository and copy it to the clipboard like this:

You can just click on the clipboard icon to copy the url
You can just click on the clipboard icon to copy the url

Next, after getting to the Unity project directory in Git Bash, use the git init command to initialize an empty local repository:

Once the empty local repo is created use the git remote add origin <copied url> command (where <copied url> represents the url copied in your clipboard) to connect it with the remote repository from GitHub:

Note: git remote refers to the type of repository that we are connecting to, add refers to the addition of it and origin refers to the name of the remote server, which is often used in the industry
Note: git remote refers to the type of repository that we are connecting to, add refers to the addition of it and origin refers to the name of the remote server, which is often used in the industry

Finally, to verify that our local repository is connected to the remote one in GitHub you should use the git remote -v command, which will show that we successfully have connected to the origin server:

This shows that now we have permission to fetch and push information from our GitHub repository
This shows that now we have permission to fetch and push information from our GitHub repository

Note: it’s possible that a new window prompted asking for your GitHub credentials, so you must introduce them to authorize the connection.

And that’s it! your GitHub repo is now connected to the local files of your Unity project. I’ll see you in the next post, where I will be showing how to make a commit by pulling and pushing information to the repository to keep an adequate track of the development.

If you want to know more about me, feel free to connect with me on LinkedIn or visit my website :D

--

--

Fernando Alcantara Santana

A passionate computer technology engineer and Unity developer that is always looking to grow in every aspect of life :).