paint-brush
A Beginner's Guide to GIT: Chapter 1by@sriram
3,071 reads
3,071 reads

A Beginner's Guide to GIT: Chapter 1

by SriramMay 8th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Hello World!

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - A Beginner's Guide to GIT: Chapter 1
Sriram HackerNoon profile picture

Hello World!

In this blog let us see what is git and how it is used in industry.

What is Git?

Git is a Distributed Version Control System (DVCS), that holds the whole history of project, including the changes. It is built with security, performance and flexibility in mind. It was developed in 2005 by Linus Torvalds the famous creator of Linux kernel.

What is a Version Control System (VCS)?

A system that records changes to a file or set of files over time is called a Version Control System. This enables us to recall a specific version later.

Why we need a VCS?

  • VCS are essential for collaboration. When many people work on same project, they will be working on shared files. There are many conflicts like only one person will have access to a file at a time. There are chances like some one may overwrite your content. In VCS, this is prevented.
  • Everybody can work on any files, without any conflicts and can merge all into a common version.
  • It is very hard to maintain different versions of the project, like naming versions, comparing two version, etc. But VSC will make these tasks simple.We can restore previous versions of the project easily and it acts as backup as well.
  • Some of previous version control tools:

  • RCS (Revision Control System)
  • SCCS (Source Code Control System)
  • Bit Keeper (Proprietary VCS, where Linux is built)History of VCS

As I said earlier, git is a Distributed Version Control System. Let us quickly look into DVCS and other previous VCS.

Local Versioning System (LVS): A database that stores different versions of files. Its main drawback is that we cannot collaborate with other team member. Everything is local.

Centralized Version control System (CVS): Here all the versioned files are stored in a centralized server. The members of team can checkout the files from the server. There were certain degree of possibilities to know what other members in the project are doing. Its drawback is every thing is stored in the centralized server. When server crashes, everything is gone. We cannot also work when server is down. Saving entire history of project in a single place is a high risk.

Distributed Version Control System (DVCS): In DVCS, unlike the other VCS, the whole project including history is mirrored into the client’s device. So even when the centralized server crashes, we can revamped from the client’s clone. This enables us to collaborate with different group of people in a different way, simultaneously.

Git vs other DVCS

Like Git we have other DVCS like Mercurial, Bazzar, Darcs. Let us see how Git stands out from these DVCS.

  1. Git thinks about data, whereas others think about the file changes.
  2. Git stores the snapshots and not the differences.
  3. Nearly every operation is local, as we have the entire history of the project in our local disk. We can work even when we don’t have internet or we have a bad network. The files will be uploaded once we get good network connection.
  4. Integrity: Everything is check-summed before getting stored (SHA1 hash).

Let’s dive technically into git.

The three states

There are three states in git

  • Modified — When some file is modified in the repo.
  • Staged — When modification are done and files are staged.
  • Committed — When staged files are finalized and committed.

How to install?

Linux:

$sudo dnf install git-all (For RPM based distributions)
$sudo apt install git-all (For Debian, Ubuntu distributions)

Mac:

$git — version

If git is not installed, it will prompt to install.

Windows:

Follow this link: https://git-scm.com/download/win

Git config

Get and set configuration variables that controls all aspects of how git looks and operates

Global Configuration

Here we will be configuring things like username, email, etc

git config — global user.name “sriram23”
git config — global user.email <your email>

Repository (or) Repo

Any directory that has a ‘.git’ directory in it are called git repository. The ‘.git’ directory will have the complete history of the project.

Creating a git repo

I will create a new directory and make it as a git repository.

$mkdir myFirstGitRepo
$cd myFirstGitRepo
$git init

This will create a directory called myFirstGitRepo and once git init command is executed, a .git directory will be created.

Cloning an existing repo

We can clone an existing remote repo (we will see about the remote repo in upcoming chapters). We can do it by using the git clone command.

git clone “https://github.com/sriram23/Battery-Tracker.git

To summarize, in this blog, we learned about Git, VCS and its history, Git installation and Git repo. In the upcoming blogs, we will explore more about git.

Thank you!