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.

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
git add command with filename in Git Bash
git add command with . in Git Bash
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
Text Editor window opened by Git requesting commit message
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
GitHub repository showing most recent commit