What is GIT?

Git is a distributed version control system. A distributed version control system maintains two kinds of the repositories (repo) namely central repository and local repository. A repository is basically a data storage area where developers can store their files. With the help of git, you can create a local repository for your project and access the remote repository in the following ways:

A developer makes changes in the local repository

Then, he pushes the changes to the central repository

The developer can also update the local repository by any files that have been put into the central repository by other developers by using the pull operation.

Why is it called GIT?

GIT was created by Linus Torvalds in 2005 for the development of the Linux kernel. He described git as ‘’the stupidcontent tracker”. Git is a British slang for a stupid or unpleasant person. Linus Torvalds described the name git as a random three-letter combination that is pronounceable, and not actually used by any common UNIX command.

What is the full form of GIT?

GIT is not an acronym; it is a British word and hence has no full form.

Why use GIT?

GIT provides the following advantages to the developers.

Collaborating with different developers:

Suppose there are three developers working on a project and all of them are making a change in the same file. It might be difficult to know who has done what changes and it may also happen that all of them make the same modifications but in a different way.

Hence, merging all the changes, in the end, may be chaotic.Git enables us to determine who has made what kind of changes and visualize everyone's work properly. Thus, it helps in avoiding conflicts at the time of collaboration.

Storing the versions of a project:

If you want to keep a track of different versions of the project by yourself then, you might come up with several questions like:

What would you exactly save; either only the changes that have been made in the project or the entire project?

How to name these versions?

How to know the difference between various versions?

If we save only the changes it will be difficult to visualize the whole project after incorporating that change and if we save the entire project every time a change occurs then, there will be a lot of redundant data as same things will be saved again and again with minor changes.

The version control system manages all these things and takes care that there is only one project i.e. there will always be one version of the project on your local machines and the other versions will be neatly packed in the central repository.

Backup of your project:

Every developer has a local copy of the main project from the central server. The developer fetches the file from the central server into the local repository which is known as the local copy for the developer.

He then makes changes in that local copy and saves those files into the central server again so that they can be available to the other developers as well.

This is helpful as in case if the central server fails, all the local copies will be present with the developers.

Even if a developer has not updated his local copy, he can have the updated version from some other developers. Hence, with the help of the git version control system, you can always maintain a backup of your project.

Analyzing the project

While developing a project you might come up with questions like:

What could be done to make your project much better?

What changes have you made?

When were the changes been made?

Were these changes right or not?

Git version control can help you find answers to these questions and analyze your project completely.

Introduction to Version Control

Developing a project is not an easy task. Many times it requires a number of developers to collaborate and work together on a single project. It may also happen that the developers are working from various geographical locations and hence they need to manage the whole project. Also, it requires keeping a track of any changes made by any of the developers in the project.

As shown in the diagram above, if all the developers would work separately at their ends and then merge the work into a single project then, it may create a lot of confusion. It will be difficult to make changes and handle any compatibility issues or system crashes at that time. Version Control Systems thus help in managing such projects.

What is version control system?

A version control system acts as a manager to your project and manages any changes made into the project from the start of the project till the end. The changes could be adding new files into the project or modifying the existing files.

Version control system creates a snapshot of the entire project every time a change occurs and saves that snapshot. These snapshots are called as Different Versions of the project.

Hence, we can say that a snapshot is the state of the project at a particular time. The version control system keeps all the versions of the software intact and hence in any case if you want to roll back any of the changes, it would not be difficult. That is the main purpose of version control systems.

There are many version control tools available such as Apache Subversion, Mercurial, Concurrent Version system, and git.

As shown in the figure below, a version control system tracks every change made throughout the project timeline. Initially, there was only one file index.html. Then, as another file was created and added to the system, the changes were recorded by the version control system accordingly.

Various types of Version Control

Local Version Control: A very simple approach to version-control is copying files into another directory. But, this approach is error prone as it is easy to forget which directory you’re in and accidentally write to the wrong file or copy over files you don’t mean to. Hence, local VCSs were developed that had a simple database that kept all the changes to files under revision control.

Centralized Version Control: A centralized version control system has a central server that contains all the versions of the files and a number of clients (developers) can check out those files from the server. This is helpful when more than one developer is working on a single project.

Distributed Version Control: In distributed version control systems the clients can not only checkout the files from the central server but, they can also take the whole repository into their local repositories respectively. If the server fails, the developers can restore the server.

Git vs. GitHub

Git

GitHub

A tool that allows creating a local repository

Allows hosting the central repository on a remote server

A version control system

A repository hosting service

You can consider GitHub just as a social network like Facebook. You can share your photos, videos, and status updates on your Facebook page and they become visible to your friends. Similarly, GitHub is a social network for developers where they can share their code with other developers.

Git Architecture

The developers fetch a code from the central repository or develop new files in the working directories (or working trees) on their respective local machines. The staging area is a file that contains information about what modifications or additions will be committed next. It is also known as the ‘index’.

Whenever the developer wants to permanent certain modifications in the project he keeps them in the staging area. From there the changes arecommitted and stored into the local repository. From the local repository, the developer pushes the changes made to the project into the remote repository so that they can be available to other developers as well.

Features of Git

Distributed: The developers develop the project files on their local machines (local repository) and then transfer them to a server (central repository). They can also fetch the files from the central repository. The developers might be at different geographical locations but everyone has a local copy of the project.

Compatible: It is not a difficult task to migrate from another version control system like subversion to git. Git is compatible with all other repositories and hence, using git you can access any central repository. Git is also compatible with protocols like SSH.

Nonlinear: It records the current state of a project by creating a tree graph from the index and we all know that a tree is a nonlinear data structure. With the help of this data structure, you can navigate and visualize all the work.

Branching: Git facilitates nonlinear development through branching. Git is the only control system which has a branching model. Branching allows developers to work on different features of the project separately. A master branch is maintained for the entire project and the developers merge their branches to this master branch. Branching makes it easy to create, delete, update, and navigate over various features or versions of the project.

Lightweight: Git uses lossless compression techniques to compress data at client side and thus, it doesn't take a lot of space.

Speed: The local repository is present on your local machine only hence it takes no time to fetch data from the local repository. Also, Git is written in C Language which is very close to the Machine Language hence; there are no run-time overheads. Git is almost hundred times faster than other version control systems.

Open Source: Git is an open source software hence; you can modify the source code if required.

Reliable: As we know the local repository also acts as a backup to our project and thus we can get the latest version even if the central repository crashes. Also, we can have a backup of the central repository if we feel like the developers are not very regular in updating the local repositories.

Secure: Git uses the SHA 1 cryptographic algorithm to identify all objects. Thus, after you make all the changes you cannot deny them. GIT creates a commit hash for every commit and hence we can check which commit has been causing any problems.

Economic: Git is released under general public license and hence is available for free to all the users. Also maintaining the central repository is not very expensive.

How to use Git?

You can create an account on GitHub first for creating a central repository. Then, you need to download git and install it on your machine to create the local repository and access the central repository on GitHub. You may also access any other central repositories using git.