Git version control is a good practice to maintain your project code, either if you are working alone or collaborating with others. It keeps track of any changes and modifications you make along the way, so you and your teammate will know what might have caused a hiccup during the development course.
In this article, we will focus on the basics of using git to version control our Unity project and host the code on Github.
Step 1-Create an account for Github. (Go to “https://github.com/” and sign up with a working email)
Step 2-Install Git. (Go to “https://git-scm.com/downloads”) and download and install the right one according to your operating system.
There is a GUI client that you can download, which is intuitive to use. But here we will simply go with the command lines.
Step 3-Create a new repository on GitHub for your project by clicking the green New button as shown below.
Once you are at the project creation page, enter your project name and description (optional). Make sure to select “Unity” to the “Add .gitignore” option when initializing the repository.
Now you can get a link to the remote repository. Copy it to the clipboard for later use.
Step 4-Link the above remote repository to our local project.
Go to your local project folder, right-click empty space, and select “Git Bash here”
Type the following command in the prompt:
git remote add origin https://the_address_you_just_copied
If any login requests prompt out, simply enter your GitHub account info. Here you have it. The next steps are to actually commit your changes to your projects.
Step 5-First commit
git pull origin master
(check if there are any updates that have not been committed)
git add .
(“.” is a regular expression stands for all, this command adds all the new files; you can also add whichever specific file you want by specifying the file)
git commit -m “a message describing the update”
(“-m” is a flag for message)
git push origin master
That wraps the most basic steps to version control changes in your local projects and host it on Github (pull->check status->add updates->commit updates->push).