Git Good with Unity
Git is one of the most, if not THE most popular, version control systems out there. It easily allows you to track your changes and to work collaboratively with anyone anywhere in the world. If you want to work in the gaming industry, You need to know Git, bottom line. Let’s take a look at how to set it up for Unity.
The first step in this journey will lead us to either GitHub or Bitbucket. This is where you will set up your Repository. There is not a major difference between the two services. They both offer free plans for you to host your project and share them if you wish.
Here’s how you create a repo on Git hub. It’s really easy.
Create your account and then log in and you’ll be able to create a repo right away.
Once you click the “New” button you it will take you to the repo set up page.
Everything here should be pretty self explanatory except the Git Ignore, Readme, and the license.
a .gitignore file is super important because it allows you to block unnecessary files that unity generates. These can clog up your project and create problems if they aren't ignored. Here is a great Unity specific Git Ignore to use.
https://github.com/github/gitignore/blob/main/Unity.gitignore
Most of these are Generated files that Unity will make if they aren’t present, so that’s why we ignore them.
A README is a file that is used to explain your project and to add anything special. You can use Markdown in the ReadMe. Here is an excellent guide on READMEs and using Markdown. https://www.makeareadme.com/.
A License, in essence, is used to determine the availably of your project for others to use. There are quite a few and it can be confusing to determine what kind of license your project needs. Luckily there are great resources out there for this.
GitHub docs on Licensing — https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository
This is an awesome site that walks you through what kind of license is right for your project - https://choosealicense.com/
Now that we have the repo set up, we need to actually install Git.
Go to https://git-scm.com/downloads and choose either the Mac or PC version and grab the 64bit standalone installer.
When you get to this screen, make sure that Git Bash is selected and that LFS is checked. We’re going to be using the command line which Git Bash provides that functionality.
Git Bash is basically the in-between communications between GitHub and the Git we just installed.
Type “Bash” into the program search on your computer to launch the terminal.
Now we need to navigate to the folder of our project. You can use the command line to change directories, command: “cd” or you can do the short cut way, which is to right click on the folder with your project and select “Git Bash Here”.
Ok, now the command line fun begins.
We need to link our local project with our remote repository that we made on GitHub.
Go to Bash which should be opened on your project and type the command, “git init”. This will initialize git in our project folder.
Now, jump back over to GitHub and go to your repository main page. There is a green drop down button “Code”, click that and navigate to the HTTPS option and copy that.
This URL will be used to link our local and remote repos.
Head back to Bash and type the command “git remote add origin (URL we just copied)”. the “origin” in the command can actually be anything, but it is industry standard to use “origin” for the name of the remote repo.
We can verify the connection by typing the command “git remote -v”.
And that’s that. We’ve successfully linked our project with with our remote repo on GitHub.