Saturday 4 February 2017

Why Git?

On this post, I would like to highlight the advantages of using Git based on my personal experience. I am currently using TortoiseGit and it helped me increased my productivity. I had used different Version Control Systems (CVS, SVN, TFS, VSS) and I think Git is far more superior than them.

----------------------------------------------------------------------------

Scenario: When I started my career, the way I version control my project is by duplicating/copying the current folder and appending some info onto it. Sometimes, I will zip it. And like for example my project folder name is: MyProject , then I will copy it and rename it to MyProject - Dec 25, 2003 Version 00.08.00 Beta – Added unit test.

I even took it one step further, I created a Python script to automate the archiving and ignore all the files the doesn't need to be stored (like all files and sub-directories on bin\ and obj\).

Problem: Most of the times, you need to see the difference of the original and modified file. It will be very difficult to diff and compare the project files using the scenario above. How git resolves it? With git log, it is easy to compare the files and you can do a personal code review before doing a commit and this is a very big plus. I can also easily see if I accidentally deleted or unintentionally modified some of the codes. Plus, every log has some comments.
Problem: Using the primitive way of copying project folders manually, you will also be copying all the unnecessary things like executables and object files which you can always generate and this may also increase the size of your archieves. How git resolves it? Just create one text file (.gitignore) and it will ignore all the files to be committed.
Problem: People thinks that archiving the project into zip files will yield smaller backups. How git resolves it? That thinking is wrong. I had an old project where I archived it using zip files. I manually ported them to TortoiseGit (and I admit, it was tedious to re-commit that project and I should have used Git in the first place). After finishing, I went to Git Bash and run git gc. Bam! My total git repository size was far way smaller than all the zip files combined!

Conclusion on this Scenario:
I personally feel that the copying of files and/or manually archiving it into zip files is not a good way of doing things. Although that Python script worked perfectly, I think that it was a waste of time.

----------------------------------------------------------------------------

Scenario: Before, the way I reuse source code modules is by copy pasting the source codes into project folder.

Problem: Maintenance problems. Updating all the copies will be very difficult. If you modify that common code and you would like all the projects to use it, then you need to copy paste the updated files. Plus, you don't have any trace-abilities. How git resolves it? Git submodules! This is one of the best features of Git that I love. I have 3 projects and they share one library which is still evolving and being updated constantly. This one shared library is a submodule of the 3 projects and they refer to a single Git repo. Whenever there are new updates, I just do a Git submodule update.

----------------------------------------------------------------------------

I really love Git and I hope I learned it a few years back. I can easily do trial and error on my codes, and if don't like the outcome, I could easily revert it using Git. I can also put my current progress on-hold without committing (using Stash) and go to different branches. I almost use it in everything (e.g. Password manager, resume/CV [I use the diff in MS Word], version control during picture editing). The logging mechanism of any VCS is important and I hope people will start using Git (or any VCS) instead of copying and/or zipping project folders.