Version control or source control is a tool that helps users keep track of all the changes on files in a project. It is like a time capsule, it allows users to go back to the versions saved before. That is, no matter what horrible mistakes you make on your files, you can always go back to the last clean state and pretend nothing happened. It is not only good for personal use but also for a group of people collaborating together on the same project. In the following paragraphs, we are going to discuss the benefits of using version control and the risk of not using it.

Assume that you are developing a web application by yourself, after working for a couple of hours, you finally have your first version done. You test the code, make sure everything works as expected, and then save the code. For the following days, you add one new feature every day and before the end of the day you test all the new code and then save the code. So far so good, until one day your manager tells you that he thinks you add too many features on the app and he wants you to remove the two features you added in the past two days. If the code you added in the past two days is very isolating from the rest of the code, then you might be able to easily spot the code block, delete them, have a quick test, and then done. However, if the code is highly dependent on the rest of the code, then you might find that it is time-consuming to go through all the files and undo all the changes since you cannot remember all the changes you made clearly. One small thing is missing, the whole application can break completely and you have to start to debug and test over and over again. Suddenly, it gets overwhelming quickly. At that time, you just realize only saving the latest version is never enough and you wish you have every different version saved.

Instead of saving a new version as a new project, version control only tracks differences which not only saves disk space but also saves your time on all the file management work. Because differences are saved, when you ask for the version created two days ago, version control can easily undo all the changes on your files immediately and accurately for you. In each checkpoint or commit you saved in the version control, you can add a message or description about the changes. These messages will be saved along with the changes you have which help your future searching on old commits. The directory that the version control tracking on is called repository. All the files in that repository are tracked unless you specified in the “.gitignore” file. Usually, it is a good idea not to track cache, large data files, and some user-specific configuration -related files. If you are the only contributor to your project and the repository is only saved locally, you might not find the “.gitignore” file that helpful. But if you want to collaborate with other people in a project, to better share your code and communicate with one another, you want your repository is not only saved on your computer but also somewhere else like Github, so that your other teammates can easily access the repository as you do. In this case, “.gitignore” is an easy way for you to control what are the files you do not want to push to the remote repository where your teammates can all see. But do not forget, files specifies in “.gitignore” are not tracked, so when you revert back to the old version, they remain in the latest saved version. So, think carefully when you edit the “.gitignore” file.

When collaborating with others, you and your collaborators may edit on the same file at the same time which can be chaotic when you tried to combine both your changes into one. Instead of manually examining all the differences and being worried about messing things up, version control helps you merge all the changes together and warn you when any conflicts are detected. Besides, since everybody is checked in their changes to the same repository, you can see all the historical changes from you and your collaborators which can help you get into the swing of things rapidly. Tons of communication time is saved and everything is logged and well preserved. Knowing that you are protected in a safety net, you can develop everything wild and creative without fear of breaking what you have so far.

The other cool thing about repositories is branches. A branch has its own version control circuit. Before having other branches merging into your branch, you are in your own world. This can be extremely helpful when you and your collaborators are working on something big individually and you do not want to have things combined together before you all finish. In this situation, it is good to create a branch for each of you from the same main branch which means you all start at the same state. Before you guys merge your branches to the main branch, any changes you have will only be in your own branch and will not interfere others branches. Then, when any of you finish your work, he or she can create a pull request or merge his or her branch to the main branch that your branches created from. In the end, all of your commits are saved in the main branch in chronological order.

Branches can also be very helpful in separating different development environments. You want your code passed all the tests in all the low-level development environment before pushing to the production environment where your customers are using. So, you and your collaborators’ branches will merge to this “dev” branch first and run tests on the “dev” environment. If tests do not pass, then you fix the bugs and make changes on your own “feature” branch and merge your branch to the “dev” branch again. If everything looks good on the “dev” environment, then you can confidently merge your “feature” branch to the “production” branch and have an official release after code deployment. Different companies may have different designs on how they use version control on their software development. No matter how different the process and the designs are, one thing that remains the same is they all find version control helpful.

There are many version control software out there including Git, SVN, Mercurial, …etc. From what I know, Git is the most famous and widely used one at the time I wrote this article. Git is also the one that I have been using, so all the things I wrote above are all based on my personal experience on Git and its compatible software. The main interface for Git is the command line which may look not so friendly for most people. So, some software like Github Desktop and SourceTree provides wonderful GUI for Git. Of course, you can do more advanced things using the command line but in most cases, GUI should be enough. If you do not like to open too many software when you are developing except for your favorite IDE, then do not worry there are so many IDE out there that already have Git included in their product. For example, if you are an avid R user like me, you can find that in Rstudio there is a tab for Git where you can see the code changes, edit commits, pull, and push code. For Python users, Pycharm also provides a Git feature. In VSCode, it has its default Git extension but if you do not like how it works, there are plenty of version control related extensions in the marketplace waiting for you to try out and find the one you love. That is, version control is everywhere and I think people in the software development world do not know how to live without it anymore especially when they need to collaborate with others. Furthermore, without the emergence of version control, the idea of DevOps is hard to implement. Think about your package will be automatically built when your code is checked in to the main repository or your feature branch is merged to the main repository. And, if the tests failed in the building process, you know what causes that since you have all the changes logged for you. The time you plan to spend on debugging is going to massively decrease and now you have more time with your family and your beloved ones.