Welcome back to the second part of our “Getting started with Git in Unity” series! Now that we have Git installed we are going to look into creating and linking our GitHub repository with our Unity project.
Let’s navigate to github.com and sign in. From here, to create a new repository we want to click the big green “New” button. Fill in the necessary information including a repository name, description, making the repo public or private, and be sure to add the Unity .gitignore file which limits using unnecessary files and ballooning our repository file size by going to “Add .gitignore” and typing “Unity.” (Fig 1)
If done correctly, your GitHub repository should look like the following (Fig 2):
To link our project to our newly created repository we need to initialize Git and add our web server with our local Unity project. Open a Git bash terminal and navigate to where your Unity project is using the “ls” and “cd” commands, or open an explorer window and navigate to your project and “right click” while inside your Unity project directory and choose “Git Bash Here” which will open a Git bash terminal in that directory (Fig 3).
Next we want to type “git(space)init” which will initialize a Git repository and allow us to track our project. To add our GitHub web server to our repository we want to navigate to the green button “Cone or download” and copy the URL, then go back to our Git bash terminal and type “git(space)remote(space)add(space)origin(space)[paste URL here]” meaning we are adding a remote server to our origin aka GitHub repository (Fig 4/5/6).
How do we know this worked? Fear not! To verify our server is connected to our project we can check by typing “git(space)remote(space)-v” if you see “fetch” and “push” then you have successfully connected to the origin server aka GitHub and are ready to work with Git in Unity! (Fig 7) But now what? In the next article we’ll go over how to commit and push your project files with GitHub.