Foundations: Don’t just save — Commit!

Now that we’ve linked Unity, Git and GitHub, let’s run through the process of communicating our changes between all three systems. When you save a change in your Unity project, Git tracks that the change was made to your project files, but that change is not saved to your repository until you commit it. To make sure that you are combining your project changes with the most up-to-date version of the remote repository, follow the four steps below each time you’re ready to add a change to your repository.

1) Pull any changes from the remote repository

In Git Bash, enter git pull followed by the name of the remote repository (ie. origin) and the name of the remote branch (ie. main). This will pull any new commits on the remote repository and merge them with your local repository to keep your local repository up-to-date.

At this point, the only commit in our remote repository is the “Initial commit” added by GitHub when we created the repository. However, since we used GitHub to create our .gitignore file, we still want to pull that file into our local repository before making any commits to ensure that Git does not track changes on unnecessary files. For more on .gitignore files, check my prior article here.

git pull origin main command in Git Bash

2) Stage your changed files

To commit your changes to your local repository, you must first tell Git which files should be included in the commit. To see what files have uncommitted changes or which files have not yet been included in any commit, enter git status.

git status command in Git Bash with changes to be staged

Once you know what files have changed, you can then add specific files to the commit by entering git add followed by the filename.

git add command with filename in Git Bash

If all changed files should be included in the commit, enter git add followed by . (single period) to add all changed files to the commit.

git add command with . in Git Bash

You can always verify all changes are added (or staged) for commit by entering git status again.

git status command in Git Bash with all changes staged

3) Commit your changes to the local repository

To commit your changes to your local repository, enter git commit.

git commit command in Git Bash

This will open a window in the default text editor titled “COMMIT_EDITMSG”, which will list all of the files included in the commit. At the top of the file, enter a message or comment briefly describing the commit. Save the file to close the window.

Text Editor window opened by Git requesting commit message

Alternatively, you can enter git commit -m followed by your commit message in quotes to avoid the text editor window.

git commit -m command in Git Bash

4) Push your changes to the remote repository

Once your changes are committed to the local repository, enter git push followed by the name of the remote repository (ie. origin) and the name of the local branch (ie. main).

git push command in Git Bash

This will add your changes to the remote repository. You can refresh your GitHub page to see the change.

GitHub repository showing most recent commit

As you build your project in Unity, remember to not only save often, but commit your changes often as well. A single commit should capture a single purpose. This four-part process to commit your changes may seem a bit laborious at first, but it can save you so many headaches later. Say it with me: Pull! Stage! Commit! Push!

Next Up: Git’s Superpower!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Agile QA using GitHub + ZenHub

Thoughts on ecologies of infrastructure

Check the Power Strip

Abstract class and Interface

Brief introduction to Inheritance and Polymorphism

Custom-tailored Configuration for Code Quality Tools in Rust

This image has an empty alt attribute; its file name is untitled-diagram-4.png

Could Edge Computing Eliminate Latency?

Highly effective Net Creation Software, Net Templates And Programming Instruments

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
Erin Brown

Erin Brown

More from Medium


Seniority Levels

CS371p Spring 2022: Sarunas Budreckis

Fantastic Symbols and Where to Find Them — Part 2