Getting Good at Git-Setting up Git for Unity
Github is a phenomenal resource for version control and it is free to use, making it an obvious choice for a solo or small development team.
Setting up version control via Git for a Unity project is also incredibly easy and intuitive. Today, I will be covering how to set up Git for your own projects moving forward!
First thing is to make a repository on Github.com.
Navigate to your account information and open up your repositories tab. If this is your first project, it will be empty.
At the top right of the screen, press the green “New” button.
Your window will now look like this.
Name your repository, and give it a description if desired.
I will be keeping this repository public, so others can view or access it.
Finally, add a .gitignore for the appropriate file type. In this case, I am using Unity.
Now press the green “Create Repository” button at the bottom.
Now open the webpage for your repository and find the green “Code” drop down menu in the top right. In the menu, click the copy to clipboard icon.
Now we need to navigate to our local project on our computer. Navigate to the project folder on your PC, right click, and Git Bash here.
A new command line window will open inside this repository.
NOTE: all git commands start with the keyword “git”
First thing is it initialize git for this location. We can do this by typing “git init”.
Now we need to add our remote location to the repository. This can be done using the following:
“git remote add origin” then on the same line, middle click your mouse to paste the repository URL we copied earlier.
Now our local and remote repositories can interface with each other.
The last step is to make our initial commit. This will save any local files to the remote location, where anyone can access them at will.
We do the following commands:
“git add .”
Next:
git commit -m “initial commit”
Finally, we need to push this commit to the remote server by doing the following:
git push origin master (or your branch name here)
To pull the changes from the remote server to your local project:
git pull origin master
And that’s the basics of using Github for your projects!