The basics: Using Git for version control (Part 2: Linking your project to GitHub)
In this post I’m going to cover the basics of creating a GitHub repository and linking it to a local project.
- Navigate to github.com and login, then on the left hand side under Repositories click the green “New” button. This will take you to the creation screen. Fill out the basic details for name, description, and privacy for your project. Note, if you would like the public to be able to view your project be sure to select public visibility, otherwise you can choose private to keep a project within your authorized team.
- For projects with Unity, you will want to check the box for “Add .gitignore” — the reason is because Unity adds many extra files that do not need to be committed when you are working in a team, namely library files and temp files. Fortunately this is an easy step! Simply type Unity into the box to apply the template for unity projects and you are ready to create your repository. This will create your initial commit with just a .gitignore file.
3. The next step is to link this to a project on your local machine. To do that, select the green “Code” button and copy the link inside. We need this to add the GitHub webserver for this project to our local project to communicate with.
3B: Navigate Git Bash to your project folder. With the link copied, hop over to the Git Bash program and navigate to your project folder. Steps for navigation from the top level directory can be found in my last post. Conversely, you can use your system file explorer to navigate to your project directory, then right click inside the folder, and select “Git Bash Here” to instantly open that directory within Git Bash.
3C: Initialize Git in our project. Inside Git Bash type the command “git init”. This will initialize an empty git repository in your unity project.
3D: Add the GitHub remote webserver to your repository. Type the command “git remote add origin [copied link URL]” where  is the link you copied from GitHub (do not include the ) and press Enter. This will connect the server and give it a standard default name of “origin”. To verify it is working correctly, type “git remote -v” and you should see a printout that you have permission to fetch (receive) from and push (send) to your GitHub repository. This means you can create new commits and pull existing commits.
4. Congratulations! Your project is now linked and you are ready to post your first commit. In the next post I’ll cover some important things to keep in mind before you post a commit to the server.