Using GIT for version control with Unity pt.1
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/
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Tenth, add the files that need to be committed using either “git add <file>” or “git add .” which will add all files in red.
Eleventh, we can now commit the files added by using the “git commit -m <message about this commit>” commands.
Twelfth, push the commit to the remote repository on GitHub by using “git push origin main” commands.
Back in GitHub, refresh the page and notice that we now have 2 branches consisting of Master and Main.
Select the Main branch, and notice all the files from Unity uploaded to this branch.
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.
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.