Installing Git, using GitHub and linking your Unity projects
If you’re not using version control with your game development projects, then you’re wrestling with doom. Version control is extremely important for keeping your projects safe and gives you the chance to go back to another point in time where your project isn’t broken. It is also vital for working in a development team.
The first step is installing Git, go to https://git-scm.com/ and click the download button for your relevant machine. Follow the installation instructions and select the default options for git.
Once git is installed make your way over to your GitHub account or create one if you do not currently have one https://github.com/
Once you’re signed into GitHub click on the new button to create a brand new repository.
On this screen, you need to enter a few details about the repository that you’re setting up. Give the repository a name that is relevant to the project, then create a gitignore file, if you’re creating this repository for a Unity game project, GitHub has a special Unity gitignore file already made for you. Select the checkbox and then type in Unity into the search box, then click on the option that appears.
There is one last thing that is needed before creating the repository, there has been an update to GitHub that turns your default branch name into “main”. You can change this here by clicking on the settings highlighted below.
The name you should use is “master”, without the quotes. This will save you some headaches in the future when we come to committing and pushing project changes. Now that the default branch name has been changed it is now time to click that big green create repository button. This will take you to a new page and there is a lot of new information on this page but don’t worry, we will start small and copy the information we need to connect the repository to our local project. Click the green code button and a dropdown will appear, you can either click the clipboard button or manually select the URL and copy the information.
We need the URL in a little bit, for now, we need to use the terminal to make our way to our project folder on our local machine. On Windows, you can right-click the project folder and select the Open Git Bash here option. Alternatively, on Windows you can open the Git Bash terminal using the search option, on Mac you need to open the Terminal.
First, we need to change directory to the correct project folder. To do this, once the terminal is open you need type ‘cd’, without the quotes. Then you can either manually type the file address and hit return or the more simple way is to drag the folder over the terminal and drop it there. This will automatically fill in the local file address for you.
After hitting return you will see the address in the terminal has changed to the project folder.
Now that we’re in the local project folder we need to initialise git inside the project. We do this by typing:
git init
The project should now be initialised for Git, next we need to connect the local project to our repository on GitHub. Do you have that URL copied from earlier? Well, if you don’t I would copy it now, as you’re going to need it.
Type into the terminal:
git remote add origin copiedURL
What does this mean? To do anything in git you need to use the keyword git, remote means a remote server and we’re adding the copiedURL to the repository and origin is the master server name.
You can verify that it is now linked by typing
git remote -v
You should now see that your project is verified. If at this point it has asked you for an email and password, they are the email and password used to login to GitHub.
That is it for this article, we will continue with Git terminal commands in a different article.