Monday, March 16, 2015

Git and Github

Many people get confused with Git and GitHub, and think both to be the same. But, in reality both are not same..

   Git = GitHub   

Git is a software which helps us handle versions of a piece of work (software code / files etc..). Git is a (distributed) version control system. It provides mechanisms for sharing that content with others and keeps track of changed to content.

Github is a web-page on which you can publish your git repositories and collaborate with other people. If a team of developers have a shared repository on GitHub, they use the content on it without ever looking at its website. The GitHub.com website provides a lot more  value on top of core git.

Let's say -- where our work on git ends, our work on github begins... (Just my personal opinion).

There are several verison control systems in the market today. But git is one of the most popular one among them. To understand git better, we need to first understand what a version control is....!!

Version Control...
When we start any new project, we may tend to store all the files realted to that project in one location, say a new folder for it. As time goes by, the files in the folder and the project keep changing. There may be situations when things can go wrong due to wrong code due to a slightest mistake in some file and we may have to revert back to the previous state (previous version). This is where we require a verison control system in place, which can keep track of all the versions and the changes we have on each version, so that it becomes easy for us to get back to the working version of the code, to make things work smoothly. Hence Git.

So we install Git on our computer and then start our work with the new project (create a new project in git after it is installed on the computer). We can also make git to keep track of the changes made within the directory (by keeping history). Then we start adding some files to the project, which becomes the first step on the new project. So we can expect changes there after (while we add different set of files or modify those files which were added in first...). Hence we need to take a backup of those and tell git to take snapshot  of those files (first set added to the new project). That becomes the first version ("commit") of those files. (first "commit").

Then make small changes to the files or add more files to the project, and take another snapshot (or do another "commit"). So that becomes a new version. Making any further changes to the project and taking snapshots of those makes newer versions. Later when we need to use any of the versions created we can switch back and forth to any version we have, and that is when we versions come into play. Hence, version control.

Git is just one of the version control tools out there, which helps in having a control of our files, and the changes made to it. This should be good for us as an individual. Apart from mere version control we may require to collaborate our work with the work of our team, when we work as a team on a project. This is when we require a distributed version control system like Git.

Collaborating our work with Git
Git helps us in collaborating our work with that of our team, when we work as a team on some project. We can make changes on our local machine and then send those changes to our collaborators and also have the changes they make appear in our machine's project directory. Git has commands which allow us to push and pull the changes to other machines as well and hence the name "Distributed Version Control System".

Both team members of a team can work and collaborate on identical copies of the file. Git allows us to work on our own copy (as-is) until we are ready to pull in our collaborator's changes and push our own changes back. But unless both team member and collaborator are working sitting next to each other, it becomes difficult to understand when exactly the collaborator will have their machine on and plugged into a network. At such a point of time, necessity of a 3rd identical copy, arises, so that both team member and collaborator can pull and push to... And that is where GitHub comes to play.

GitHub
As summarized above, the need for a 3rd identical copy leads us to a tool like GitHub. At its core, GitHub is just a place to store our identical working directories or repositories (repos). The word GitHub says that all - hub of git repos. :). GitHub has other features as well other than just providing the 3rd identical copy, like giving us a nice website that allows us to compare the changes and manage user accounts.

GitHub is not just a hosting service which let us push our code repo to make it public by pushing it, in one shapshot (commit), at the end of the day... But the main purpose of GitHub is for collaboration purpose. So we need to commit every small change which gives us benefits of commit early and commit often. As early commits with our comments along with our code will let other understand our thought process and make them to suggest more mature ideas or code. So we can work faster to achieve better output soon. The earlier commits might be mostly experimental.

Now if we don't want to make our code public by putting it into GitHub, we can put them to a private repo and pull in collaborators by invitation only.. As we have several alternatives to GitHub which help us have our own private repos as well. Bitbucket is one of those Git hosting services, which helps us create and maintain a private repo (free).

Interested to learn further...!!
If reading the above made you interested to learn Git / GitHub further... then I'd say the best thing is to learn or have a better idea of Git rather than GitHub. GitHub is in reality an interchangeable servie which allows us to host our Git repo, so if we learn Git first that would make more value.

The best way to learn Git is to go online and search for documents on Git. There are several good documentation available online which would give us a good understanding about Git. Once we are good to try Git, we can visit the following link which would be a good place to start with...

Try Git...

Good luck...!!

No comments: