Setting Up Unity: Part 2 — Git

Cris A
5 min readApr 30, 2021

Welcome to the second part of the Setting Up Unity series. If you haven’t completed the steps in the previous article: click here.

This engine can be a little intimidating at first

In this part we’ll be installing git. Git allows us to share our project with team members, work on a different part of the game without breaking the main application, and go back in time if we make a mistake.

Install Git

We will need this for the course, so go get git here: https://git-scm.com

Once we download and install it, we have this new application called Git Bash.

Set up Git User Info

If this is your first time using git, you have to type your email and user name(replace the ones in the example with your info)

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Create a GitHub Repository

Now we need to go to github.com. If you don’t have an account, “Sign up” to create one. This is a website where we can store our projects and share them with a huge community of programmers. We can modify and add to our github projects with Git.

Once you have an account, create a repository where you will put your project files. Make it public and select gitignore > Unity.

Git Init your Local Unity Project

Remember the project we created last time? That project is stored somewhere in your computer. Go to the Unity Hub, select on the three dots and click “Show in Explorer”, enter the folder where the project is and right click for “Git Bash Here”.

You should be in a folder with the name of your project. Now that we are here, type:

git init
note the little blue text, tells us that our project is now using git

You do this command every time you have a new project. All it does tell git that our Unity Project is ready to be used.

Set Up Git lfs

Next we need to install an extra part of git: git-lfs.github.com

This allows us to use large files for video games, like images, sounds, special effects, 3D models and animations. run this command once you download and install it.(You only run this one command once per account.)

git lfs install
git lfs track "*.psd"

This command creates a file named “.gitattributes” on our project folder, go to this link ,and copy paste its contents.

Link Unity Project with Github Repository

Now we need to connect our Unity project in our computer to the project on GitHub, so go to your new GitHub repository and copy the link given here.

Your project’s URL will look different.

Back on the Git Bash terminal, type this and paste your own url like I am doing here.

git remote add origin YOUR-URL

You might need to sign in with your GitHub account.

Now, to get that lonely .gitignore file from our Github project into our computer, we will do these commands:

git pull origin main
git checkout main

Now we see it in our project folder.

Add, Commit, Push to Repository

Our Github Project is still kind of empty, so let’s push everything we have changed in our computer.

Now open your Unity project and create a new script. VSCode will launch and you can now see your project has some notifications on the left side of the screen. Visual Studio Code knows that we are using Git on our project.

Everything we see here are the files that changed. First you add the files on the “+” icon, then type a message, press the commit checkmark, and finally push.

First we stage all changes.
Then we type a message and click the Checkmark to Commit.
Finally, we push! At this step, if this is your first time committing from this machine, you will get a prompt to sign in to your Github account.
Now everything is on github!

“Git Add -> Git Commit -> Git Push.”

We do this every time we want to add a file from our computer to our Github Project. From that point you can share it with others and even invite friends to collaborate.

There is a lot more to Git, this is just the start. We’ll learn more about it as we work with others and encounter problems while making our games.

This is what we did so far:

  1. Install git and git lfs.
  2. Sign in or Sign up to github.
  3. Initialize git on project folder. Create git lfs file.
  4. Connect github repository with local project.
  5. Pull .gitignore from Github
  6. Make changes on your project, then add, commit, and push to repository.

We did it ! We installed Git and set it up with Unity and VS Code.

Final part of this setup series is coming up, don’t worry, there are no more installs in the next part :)

--

--