Let us assume you are a solo programmer working on a project. You will try to achieve your requirements without concentrating on adding extra features initially. Now you have completed your project with no additional features. And then naturally we will get tempted to add more features. You are showing a demo to your clients with those features, but they are not actually happy with those new features. So, you will eventually remove it.
Surprisingly, someday they think that those features are cool and ask for it again!! You would have stored that code somewhere like dropbox (If you have not stored those codes anywhere then good luck). But don’t you think that’s a lot of work?
It’s natural in software development that sometimes we feel that the previous version of our product was good. We just cannot maintain a copy of every version as files on dropbox. What if we had software to control those versions? That’s exactly what Git does to you. We can use another version control but why Git? That’s because earlier people used a centralized version control system and now they use a Distributed Version Control System.
In a centralized version control system, we have our existing code on our machine and a server will contain the previous version of the code. We have our code backed up, that’s fine. What happens if our server crashes or gets hacked? What if we are traveling and we don’t have an internet connection? Simple, we will lose all our data.
Whereas in a distributed version control system, our machine also has a local copy of the code that is on the server. In this way, every developer has their own copy and therefore “distributed” version control system.
Git is completely free and open source. If you use a mac, Git is preinstalled. Now, do we necessarily need to host our server? No, we can use GitHub, BitBucket, etc.
Git maintains version control based on the commits which we make. Commit is nothing but saves our code to git. We can go back and forth to every commit we made.
Git basically contains something called repositories which contain a collection of files of various different versions of a Project. These files are imported from the repository into the local server of the user for further updates and modifications in the content of the file.
We can also create a branch on the repository. Let’s say, we have 2 branches namely dev and prod. As the name suggests, we have our production code on the prod branch and development code on the dev branch. Whenever we have completed our development we can always merge dev and prod branches.
In order to use git, you can either use the command line or GUI. I personally use Git desktop. In case you are going to use the command line, refer to this cheat sheet by Atlassian. Happy Coding!!!