Objective: Git is one of the most popular version control systems that support collaboration among developers. In this article, I’ll walk you through the process of setting up Git for your Unity projects.
Step 1: Download and Install Git for Your Device
The first step is to download and install Git for your device. Git supports three main operating systems: MacOS, Windows, and Linux. After downloading Git, you can double-click on the application and follow the prompts to install it.
Step 2: Open Git Bash and Navigate to Your Project Folder (aka Project Directory)
Open up your Git Bash by pressing the “Window” key, typing “Git Bash” and hitting “Enter”. A Git Bash console should appear.
Navigating Git can be a bit confusing for beginners and here is a cheat sheet for Git commands to make your life easier. Suppose you have a Unity project located in a folder called “My Project” with a path of Desktop/Unity Projects/My Projects. Here is how you can navigate to the project folder using Git commands:
Note: if your project’s name has spaces between words, you’d have to wrap it with double quotes.
After following these steps, you should be in the project folder.
Step 3: Set Up a GitHub Repository
If you’re new to GitHub, it is a web-based platform for collaboration on projects among developers. A GitHub repository is like a container that holds all the files of a project, serving as a centralized hub.
You can create an account at https://github.com/. To create a new repository, click on the “New” button in the “Top Repositories” section.
You will be taken to a page where you’ll need to complete the following items:
- Fill in the Repository name field.
- Select “Unity” as the option for the “.gitignore template” dropdown list (this will help prevent Unity from collaborating on certain files in this project).
Once finished, click “Create repository,” and you’ll be taken to your repository page.
Step 4: Link Your GitHub Repository to Your Local Machine
In your project folder in Git console, type the command “git init” to initialize Git repository.
Then you’d need to add the remote server (GitHub) so we can communicate with it by typing the command “git remote add origin [repository URL]”. You can get the repository URL by clicking on the “Code” button and copying the URL under the HTTPS tab.
So our git command will look like this:
We can verify if our repository has been linked using the command “git remote -v”. You will see that we have successfully established a connection to our GitHub repository.
This indicates that we have permissions to push to and fetch from this origin server. Now you’re ready to create and push commits to the repository.