Introducing Git

While working in Unity, whether you are experience or just started learning there is a possibility that you will develop an error or two. Imagine you have spent two months developing a game only to realized something went wrong and you cannot remember when.

Git is a version control system, meaning with a simple command you would be able to revert your project back to its functioning state. Setting up Git and is remarkably simple and only takes a few minutes to set up.

First, you will need to download Git HERE

If you are a Mac user, you will need to get your copy from HERE

Once the download is finished, you will need to install, which takes only a few more clicks, and you have done it! Now you are the proud owner of your very own copy of Git. Of course, now you will want to set up your project with Git.

Start a new project in Unity and for the sake of the example I’m going to call it “GitUnity.” Once you have named it you can create and wait for Unity to open.

Once Unity is open you will go to the project file and right click and select Git Bash Here. that will open git to the project directory. Once there you can enter the command “Git init”

This command will start a Git Repository allowing you to make Git commands within. Every command in Git starts with the word Git. (git help, git branch, ect.) Now you are ready to make your first Commit. Commit is like a save state of your repository. Before we start making Commits let us talk about some key phrases.

Working Directory is the file on your console where you save your work.

Staging Area is the intermediate area from your working directory to your repository. Here is where you will add files and assets to your repository using Git commands.

Repository is a hidden folder Git uses to track all your commits “Save States” for your project.

Now, let us start with your first Commit. A save state to the beginner of your work, to get you in the habit of making commits. You will need to add files/directory names to the staging area. First, you will need to see what needs added.

To see this, you simply type the command “Git Status”, and this will show you a list of untracked files in red text. From here you can use the add command “git add ‘file name’” Doing so one by one is a fine method, however, you could use “git add .” and it will add everything with one simple command.

With everything added/tracked you can now make your first commit. Use the command “git commit -m “title of save state” The title must be in quotes and this will be the name you would see, so name this save state something you’ll be able to identify and know exactly where in the project’s life this commit is.

Here is a quick list of commands for the commit

git status

git add .

git commit -m “Created GitUnity”

Now, with the power of Git your future Unity projects will be built with the safety of earlier bug-free versions of itself. With every new asset or script added to your project the more commits you should make. Hope you enjoyed this quick rundown on this powerful ally that is Git!