Setup Git with Unity3d for Commercial Development — Part 2 First Commit

Click Here for Part 1 — where we set up Git and GitHub, along with our first project and first Repo.

Learning the Day-To-Day Git Work Process

The initial release of Git was in 2005 so it has over 16 years of improvements and features. Gits full power can literally be someone’s full-time job to maximize.

We don’t need to worry about all that power though, we just need to know how to work in it daily as a developer (or maybe a designer or artist).

Github’s mascot Octocat

First Some Simple Terminology

A “Commit” is saying we are backing our changes up to our Local Repo, so it’s the act of committing our changes into the Version Control System. To do a commit we first have to “Add” the changes we want to commit.

A “Push” means we are sending the committed changes to the Remote Repo, while a “Pull” is downloading changes from the Remote Repo. We use the terms push/pull for commands in place of terms like send/download.

The standard basic routine is we “Pull” to get the latest files from teammates, we check to ensure nothing conflicts or breaks. Then we “Add” and “Commit” our files to save a revertable backup of our changes. Finally we “Push” to GitHub so others can have access to the files.

Your first Commit & Push

There are many workflows and tricks with Git to avoid potential issues or just simplify how teams work together. For now, we’re focused on learning in a solo private repo, and in later articles tackle best practices on pulling work down without losing your changes, “stashing”, and handling “merge conflicts”.

As discussed in the terminology above, we must first “Add” before we can “Commit”. And we must “Commit” before we can “Push”.

But before all else, we should “Pull” down changes. Even though this is a new project if we double check our GitHub there is a very important file in our Remote Repo on Github.

We need to pull down our “.GitIgnore” file.

Why we need .gitIgnore

Large software projects like Unity3d projects have a lot of generated files, files we don’t really need to upload to the source control as they’d either take up space or are meant to only stay on the local computer.

How to Pull from GitHub

Pulling is pretty straight forward it’s simply this line of code

git pull origin main

“origin” is the default git name for the special remote repo URL we set up in Part 1. While “main” is the default branch name we have defined. You can also just use ‘git pull’ but this example was shared so you can see why it works.

Now you should see a .gitignore file in your project folder. Using any text editor, like Notepad, we can see a lot of work GitHub saved us with their Unity template. We won’t go into gitignore now but know it basically means “do not upload this”.

Psstt if you don’t see the “.git” folder on your end that’s fine, its a hidden file for a reason

Now we can Add Changes

First, let’s understand “why” we need to add. If we use ‘git status’ we can see a lot of red lines. Red lines are all the “new” files that we have in the project, and we have to selectively define exactly what we want to add.

If you run ‘git status’ after adding but before commit it’ll show up green saying “new file”

So we can go through each of those items and say ‘git add Assets’ and so on, but that’d be exhausting. Instead, we have a special symbol to say “all” by using a period.

git add .

And now all of the changes have been added and running our status command we’ll see all the lines are now green!

How To Commit

Now we can Commit, there’s just one special thing we need which is our commit “message”. A message is simply a note we add to the commit so we can see what changes we put into the version control system.

So let’s do a simple commit with a message just saying we created a new Unity Project.

git commit -m "Created a new Unity Project"

Now we have our changes saved in our Local Repo! We just need to get it to GitHub our Remote Repo so it’s securely backed up online.

How To Push to GitHub

To push your Local Repo changes (which now contains our one new Commit), we simply need to simply say ‘git push’ but as it’s our first time we need to assign a default push location.

git push --set-upstream origin main

Again just like the pull, the ‘origin’ is the default remote repo which is GitHub and ‘main’ is our default branch. In the future, we can just use ‘git push’.

And well that’s it. You just made your first Git Commit and Push!
If we refresh GitHub we can even see our Unity Asset files!

We can also see the time they were committed, and how many commits our project has.

Routine Commands

Now that all the setup is done it’s really just these four simple routine commands you will use throughout the day.

git pull
git add .
git commit -m "Fixed Bug #123"
git push

Congrats! You Can Now Use Git

You now know enough to start using Git daily to have a secured backup system to work on a commercial product solo.

You’d just use your routine commands and commit/push whenever you want a retrievable backup of your project. It’s best to commit after a bug fix or a new feature is added, plus it makes adding meaningful messages much easier!

You can learn the rest of the Git Bash commands as you need to.

What’s Next — LFS

If your working on a public project, or a team project, there’s lots more to learn. From dealing with licensed assets, avoiding bad merges, and automation improvements.

The most important one for Unity3D projects though is setting up LFS or Large File Storage. You’ll need this for solo or team projects as most commercial Unity Projects are going to max out Git’s default 1GB storage. So that’s what we’ll be diving into next!

An Austin TX Unity3d Developer with a unique background in marketing, design, & software development leading digital web agencies to success for the past decade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store