Setting up GIT For Unity
What is GIT
GIT is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management (SCM) in software development. SCM is the task of tracking and controlling changes in the software.. If something goes wrong, SCM can determine what was changed and who changed it. SCM is an essential part of modern-day software developer practices. Between collaborating with a team working on different aspects of the software, being able to revert back to a known good working copy when something goes wrong, or to keep development from final release.
One of the common combination of tools that we have to use as a Unity Developers for SCM is GITHub and GIT.
How to install GIT
First go to https://git-scm.com/downloads
I am using Windows so I am going to download the windows version by clicking on Download 2.31.0 for Windows.
After Downloading GIT run the installer, no need to make any changes to the defaults, just accept the user agreement and click next until it starts installing.
Integrating GIT GITHub and Unity
Go To https://github.com/ and log into your account, if you do not already have one create an account. On the left hand side of the screen Click on the New Button next to the word repositories to create a new repository.
Give your repository a name and a description.
Make sure to click the Add .gitignore and choose Unity from the drop down list. Feel free to also add a read me file and choose a license if you want, these are not required.
Then Click the Create repository button
Now Create your Unity Project.
Once your UNITY Project has been created right click on the Assets Folder and select show in explorer. This will open a window where your Unity Project is Stored.
Right Click and select Git Bash Here, this opens the command line prompt for GIT.
Now you have to initialize GIT and link the repository. The first command that you need to type is git init
Now in your GITHub repository (the one we created early on the internet) select the green Code Button. Make sure HTTPS is underlined (if not select HTTPS). Then click on the clipboard icon which will copy the link to your repository.
Now in the GIT Bash console type git remote add origin
Then right click and select paste.
Then hit the enter key this will link your GITHub repository to your GIT and your Unity project folder.
Now verify the repository with git remote -v
Now we need to Pull the main branch, git pull origin main
Lets check the status of our repository, git status
It looks like we have untraked files (all the files listed in red) and nothing committed to the repository. Let’s add all of the files to the repository, git add . don’t forget the period after add. The period indicates that we want to add all of the files. Now we will see a bunch of warnings about LF (line feed)which is normal as GIT is converting all of the line feeds.
Now lets Make a Commit with a message, git commit -m “Message” i.e. git commit -m “Initial Commit with new Unity Project Created”
Now lets push our project back to the repository, git push origin main
With everything Done our repository on GITHub should now contain the newly created UNITY project.