Day 2 — Integrating GIT with Unity Part 2

Connor Fullarton
4 min readMar 16, 2021

Hey and Welcome!

Now we get to the interesting part on all this, the actual bit that makes version control fantastic to use.

Pull, Add, Commit, Push

Before we start making edits in our Unity project we’re going to want to get the current files in the project into our Github repository. The following steps you’ll want to make sure that you’re doing them in order so that you can avoid any merge conflicts with the project or any project you may be working on especially if it’s a group one with multiple people accessing and committing changes to the one repository.

git pull origin master

Typing this one out first you’ll be able to pull in the current files from your repository which will be just your gitignore file intially but definitely a vital one.

*If you find that you’re getting an error here you’ll most likely need to do git pull origin main instead as that looks to be the current default branch name you get when you first create a repository, more on branches later. You’ll also want to make sure that you don’t have your project currently open in Unity as that can cause issues at this step as well.

git status

This command will show any changes that have happened in your project that aren’t a part of your Github repository. Running this for the first time you’ll most likely see a lot more red text than here.

If I wanted to stage the change I have in my example here I would type out the command git add Assets/ however it can be tedious to add in everything manually especially with larger projects so you can make us of this command to begin with:

git add .

The period in the command there just means that it’s going to stage everything associated with the project for the commit. If you run git status it will show you what’s been staged and ready to be committed.

Only two steps left now, next up we’ll be committing the changes to be pushed into the master branch in the Github repository:

git commit -m “Your message”

The -m here stands for message so you can put in anything between the quotation marks but make sure it’s something related to the changes you’re committing.

In the example above I added in a new UI Manager script to the project and made sure to explain as such in my commit message so that anybody else with access to the repository will be able to tell immediately what the new changes are. Now that that’s all sorted it’s time for the last step in all this.

git push origin master

Finally with this last command here your project files will have been pushed to your repository. If you go to the repository in Github you’ll now see all the files there along with the commit and message you left with it.

Ok so everything in order you’ll be doing these commands:

  • git pull origin master
  • git status
  • git add .
  • git commit -m “Your commit message”
  • git push origin master

The git status one can be optional but it’s handy for keeping track of file changes in your project. If you’re making sure that you’re doing everything in the order I’ve shown you here you’ll be able to avoid most merge conflicts with other collaborators working on the project.

Most conflicts is not all conflicts though so there’s one more thing we can do with GIT which is my favourite part about it and that’s branches which I’ll be covering in the 3rd and final part.

--

--

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.