Friday, 29 December 2017

Git (version control)

Q-What is Git ??
Ans- Git is a Distributed Version Control tool that supports distributed non-linear workflows by providing data assurance for developing quality software.

The motive of Git is to manage a project or a set of files as they change over time. Git stores this information in a data structure called a Git repository. The repository is the core of Git.
To be very clear, a Git repository is the directory where all of your project files and the related metadata resides.

Generally We have two type of version control system
1-Centralized Version Control System (CVCS(SVN-Subversion)).
2-Distributed Version Control System (DVCS(Git)).

1-Centralized VCS(SubVersion)

Centralized version control system (CVCS) uses a central server to store all files and enables team collaboration. It works on a single repository to which users can directly access a central server.

Note- Here repository is new word---Repository  is place where you will have all your code.


The repository in the above diagram indicates a central server that could be local or remote which is directly connected to each of the programmer’s workstation.
Every programmer can extract or update their workstations with the data present in the repository or can make changes to the data or commit in the repository. Every operation is performed directly on the repository.

it has some major drawbacks. Some of them are:
  • It is not locally available; meaning you always need to be connected to a network to perform any action.
  • Since everything is centralized, in any case of the central server getting crashed or corrupted will result in losing the entire data of the project.


Distributed VCS
These systems do not necessarily rely on a central server to store all the versions of a project file.
In Distributed VCS, every contributor has a local copy or “clone” of the main repository i.e. everyone maintains a local repository of their own which contains all the files and metadata present in the main repository.

You will understand it better by referring to the diagram below:
Advantage suppose your server fails its fine you have local copy
so every machine every developer have own copy so this called distrributed
In this digram we are distrubting repository
As you can see in the above diagram, every programmer maintains a local repository on its own, which is actually the copy or clone of the central repository on their hard drive. They can commit and update their local repository without any interference.
They can update their local repositories with new data from the central server by an operation called “pull” and affect changes to the main repository by an operation called “push” from their local repository.
The act of cloning an entire repository into your workstation to get a local repository gives you the following advantages:
  • All operations (except push & pull) are very fast because the tool only needs to access the hard drive, not a remote server. Hence, you do not always need an internet connection.
  • Committing new change-sets can be done locally without manipulating the data on the main repository. Once you have a group of change-sets ready, you can push them all at once.
  • Since every contributor has a full copy of the project repository, they can share changes with one another if they want to get some feedback before affecting changes in the main repository.
  • If the central server gets crashed at any point of time, the lost data can be easily recovered from any one of the contributor’s local repositories.
After knowing Distributed VCS, its time we take a dive into what is Git.

Better how? - Better to manage your code.
How to manage? - Helps maintaining and keeping track of different versions of your code.
Versions?- When you code, you tend to keep adding let’s say modules, maybe bug fixes etc. basically meaning changing your initial code. But sometimes, new addition do not work and you want to go back to the state where it worked.
In such cases, tools like Git comes in handy, because it had been maintaining your changes inn code and preserving every version. So, you can revert back anytime.
How does Git identify changes?- So, every time you make a change in your code, you need to “commit”. Each commit gives you a snapshot of your code.
Where does Git store all these changes?- In a repository. Repository can be thought of a data space where you can store all your files related to your project.
Mostly, you work with two repositories - local, which resides in your system and remote/central which mostly lies on a remote machine - something like GitHub.
Ah! Here comes GitHub!
Technical definition - It is a website where you can host your repository and share them with people.
Friendly definition - It is a Facebook for programmers. Instead of pictures and 
Differences between GIt vs SVN:-
The key difference is that it is decentralized. Imagine you are a developer on the road, you develop on your laptop and you want to have source control so that you can go back 3 hours.
With Subversion, you have a Problem: The SVN Repository may be in a location you can't reach (in your company, and you don't have internet at the moment), you cannot commit. If you want to make a copy of your code, you have to literally copy/paste it.

No comments:

Post a Comment