Version Control with Git in Unity
Alright!
Before getting into the tech side of version control, let me get the juice on the table.
Assume that you are writing a story. (For those, who are not much into writing, imagine some other task that requires multiple edits.) You know that to have a complete story in place, you may take at least 50–100 drafts of multiple chapters before saying enough with a final version.
How do you save those drafts? Well, make a folder and put all files in there. Now, if you have walked down that path, you must have faced a situation where some part that was written a few days/weeks ago is still in your memory and despite writing multiple versions, that part tops your preference. However, the latest versions have some bits that you would like to incorporate with the earlier version and make it perhaps the best of all.
Unfortunately, you would not be able to recall which version holds which good bit. Solution? You skim through all drafts and extract the bits that you want and then go ahead with the final amalgamation. What do you think about the efficiency of this approach? I’d say extremely demanding way to address the concern.
What if there was a tool that could tell which draft contains which changes? I think it’d be a tool you’d purchase right away so that you could save time, effort, and mostly motivation. This is what version control does.
Essentially, it tracks changes done in your project. Those could be done either by you alone or multiple collaborators in a project with scale. In short, Git is a distributed version control tool where each act of change by every team member gets recorded and you can revert back to any change point during the project life cycle.
Now, let's get to the tech side of version control and its need in Unity.
While making a game project, you are bound to have multiple iterations of changes. To hold those specific details, you will have to use git as your version control tool and any other server service such as Github, Bitbucket, SourceTree, etc where you are going to store your versions.
Let me walk you through a quick setup process.
- First, visit this site https://git-scm.com/downloads & download the appropriate version according to your OS.
- Let the default ticks be unchanged, install it by clicking next till the end.
- After successful installation, you should be able to open the git bash tool which seems like a command-line interface.
Here is a little navigation tour in Git bash
- There are two basic commands ls and cd that you would have to use at the doorstep. ls lists out all directories on your desktop and cd allows you to change directories. (Tip: When you type a few initials and press the tab key, the autocomplete function will get the full name of the folder.)
- The other way to directly run bash is to go into the folder where you have stored your unity project and right-click to see “get bash here” option. This would get you going instantly with the main work.
Now, the next part is connecting it with the service where you are going to host your versions. I am taking Github as an example here.
- Go to https://github.com/ and sign up.
- Now, click on the “start a project” option after you have logged into your new account.
- Now, you shall see the following page where you have to enter just a few details.
- Now, you should have landed on the project page. Let it be open and shift to your local system to start git bash where your project is located.
- Now, write command git init. (This is to initialize the repo.)
- Now, write command git remote add origin <URL>. (The URL shall be available in your Github repo.)
git remote means you are making a repository of remote type. add lets git know about a brand new addition. Origin is the name you have given to the remote repo. Although you could give name of your choice, origin is a set standard in the industry. URL links the server with your local git bash.
- Done. Now you should be able to work further with version control commands like -v (to check version), pull, add, commit, push, etc.
Hope this was helpful enough to get you started with git and GitHub connection with a unity project.
Thank you very much