Using GIT for version control with Unity pt.1

Rhett Haynes
6 min readMay 19, 2022

Objective: A quick crash course in using GIT. We will use GITHUB to create a repository, and GIT BASH to add changes in our Unity scene to the repository by pushing them onto our GITHUB server.

When working on projects that multiple people will need to collaborate with each other in the process of making it, we will need a version control system to help us with this. That’s were GITHUB will serve as our version control system to store our projects, and GIT BASH will allow us to add any new changes to our projects on the GITHUB server.

First, we need to sign up with GITHUB at their website: https://github.com/

GitHub webpage.

Create a new repository by creating a new repository name, writing a description of this repository, make it either Public or Private, add .gitignore template with Unity chosen as this will not track any Unity files that we don’t need.

GitHub repository created.

Second, we need to download and install GIT either for PC: https://git-scm.com/ For MAC: https://git-scm.com/download/mac

Select either 32-bit or 64-bit according to the computer system you’re using. Then, keep selecting NEXT through the default settings until you reach INSTALL and install GIT.

Third, create a new Unity project or use an old project that will be linked with our GitHub repository. We will use GIT BASH to manipulate new file changes from Unity that will be uploaded to our remote repository.

Fourth, to open GIT BASH at our project’s folder destination, there is 2 ways of doing this. The 1st way is to open GIT BASH and use the CD command which stands for Change Directory. If you don’t know exactly where your project folder is located, use the LS(list) command.

Used git’s LS command to view the list of files and folders on our drive.

As we use the LS command to see the folders on our hard drive, when we find the folder we want to navigate through we will use the CD command. The CD command stands for Change Directory which will allow us to make the directory we changed to the active directory. Also, we can use a shortcut to autofill the name of the folder by spelling out the first few letters in the word, and pressing the TAB key which will fill in the rest of the file’s name.

Used the CD command to change directories.

If we have files whose names have multiple words in them, we will need to add quotation marks around the name of the folder we want to change to.

Typed the name of the folder inside quotations to change directory.

Another way to go straight to our project’s location is to go to the project’s folder. Then, either right-click on the folder or inside the folder and select “Git Bash here.” This will open the GIT BASH editor, and place your working directory at the project’s location.

Right-click inside the project’s folder to open GIT BASH at this particular point.

Fifth, before we do anything inside of GIT BASH, let’s copy the URL address of the remote repository. Back in GitHub, click on the green CODE drop-down list, choose HTTPS, and copy the URL address.

Copied repository’s URL address.

Sixth, in GIT BASH we need to use the “git init” command to initialize GIT. Then, to create a new connection to the remote repository, use the “git remote add origin (URL address of the repository from GitHub)” commands. Now to check and see if it went through, use the “git remote -v” command which we should see FETCH and PUSH after the file path.

Initialized and added a new remote repository.

Seventh, before we commit any changes from the Unity files, let’s change the branch we will push and pull from in the remote repository. Instead of using MASTER, we will use MAIN as the primary default branch to work with as this will be the working branch name used as the industry standard. Use the command “git config — global init.defaultBranch main” as this will change the default naming in git. Also, if your current local repository has the Master branch, use the following commands “git branch -m master main” to change it to MAIN.

Changed the default name for the primary branch in our repository.

Eighth, we can now see what untracked files that need to be committed by using “git status” command. The files in red indicates that we need to add and commit these files before pushing it to our remote repository.

Used git status to see untracked files.

Ninth, if we have files that are larger than 100MB, they will not be added or committed as GitHub has limits to file amounts. Instead, we can use the LFS(Large File System) to replace large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on our remote server. Every account using Git Large File Storage receives 1 GB of free storage and 1 GB a month of free bandwidth.

To download GIT LFS, go to https://git-lfs.github.com/ Go back to GIT BASH, and use “git lfs install” command to install the Large File System.

Installed LFS to handle files larger than 100MB.

Tenth, add the files that need to be committed using either “git add <file>” or “git add .” which will add all files in red.

Added all files to be committed.

Eleventh, we can now commit the files added by using the “git commit -m <message about this commit>” commands.

All files added were committed with a message.

Twelfth, push the commit to the remote repository on GitHub by using “git push origin main” commands.

New files pushed to the remote repository.

Back in GitHub, refresh the page and notice that we now have 2 branches consisting of Master and Main.

Main branch pushed into the repository joining the Master branch.

Select the Main branch, and notice all the files from Unity uploaded to this branch.

Main branch with Unity files pushed into the repository.

Finally, to change the default branch to Main, go to Settings. Choose Branches, under Default branch select the “Switch to another branch” arrows, change from Master to Main, click on Update, and click on “update the default branch” to make these changes permanent.

Default branch changed from master to main.

If you want to delete the MASTER branch, select Branches, go to the MASTER branch and click on the trash can to delete this branch.

Deleted the master branch from our repository.

--

--