Why Use Git?

What is Git

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. As i mentioned Git is a distributed version control system, meaning your local copy of code is a complete version control repository. These fully-functional local repositories make it is easy to work offline or remotely. You commit your work locally, and then sync your copy of the repository with the copy on the server. This paradigm differs from centralized version control where clients must synchronize code with a server before creating new versions of code.



Git’s flexibility and popularity make it a great choice for any team. Many developers and college graduates already know how to use Git. Git’s user community has created many resources to train developers and Git’s popularity make it easy to get help when you need it. Nearly every development environment has Git support and Git command line tools run on every major operating system.

Now, let’s understand what is Version Control.

Version Control is the management of changes to documents, computer programs, large websites and other collection of information.

There are two types of VCS (Verion Control System):

  • Centralized Version Control System (CVCS)
  • Distributed Version Control System (DVCS)

Centralized VCS

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.

Please refer to the diagram below to get a better idea of Centralized version control system (CVCS):

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.

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(programmer) 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.

Please refer to the diagram below to get a better idea of Distributed VCS

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 (Distributed VCS) by an operation called “pull” and affect changes to the main repository by an operation called “push” from their local repository.

Basic Operations

The following is a summary of basic git operations:

git add

Puts current working files into the stage (aka index or cache)

git checkout

Replaces the current working files with files from a branch.

git checkout -b

Creates a new local branch from the current branch’s tip.

git clone

Clone an existing repository into a new directory.

git commit

Commits staged changes to a local branch

git commit -a

Commits all modified files to a local branch (shorthand for “git add” followed by “git commit” for each modified file)

git pull

Fetches remote changes on the current branch into the local clone, and merges them into the current working files.

git push

Uploads changes from all local branches to the respective remote repositories.

git reset

Makes the current branch point to some specific revision or branch.

git reset –hard

Makes the current branch point to some specific revision or branch, and replaces the current working files with the files from that branch.

 

Why Use Git?
Show Buttons
Hide Buttons