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
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
After the installation, launch Git Bash and a terminal will be shown to you:
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.
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.
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.
Then, you should get the url at the right top of your repository and copy it to the clipboard like this:
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:
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:
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.