A Beginner's Guide to GIT: Chapter 1
Tech Fan | Software Engineer | Occasional Blogger
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?
- 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.
- Git thinks about data, whereas others think about the file changes.
- Git stores the snapshots and not the differences.
- 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.
- 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?
$sudo dnf install git-all (For RPM based distributions)
$sudo apt install git-all (For Debian, Ubuntu distributions)
$git — version
If git is not installed, it will prompt to install.
Follow this link: https://git-scm.com/download/win
Get and set configuration variables that controls all aspects of how git looks and operates
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.
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.
Subscribe to get your daily round-up of top tech stories!