Git Tutorial

"This is git tutorial designed for beginners and intermediate learners to master git concepts."

By Shivam

01/07/2025

👋🌍

A Seamless Guide To Master Git

This chapter will be about getting started with Git. We will begin by explaining some background on version control tools, then move on to how to get Git running on your system and finally how to get it set up to start working with. At the end of this chapter you should understand why Git is around, why you should use it and you should be all set up to do so.

What is "version control" and why should you care?

VCS stands for Version Control System. It is a tool that helps manage and track changes to source code or other files over time. VCS is essential for software development and other projects where maintaining a history of changes, collaboration, and versioning is critical

Why do we need VCS(Version Control System)?

A Short History of Git

Git, a powerful version control system, was created by Linus Torvalds in 2005 to manage the development of the Linux kernel. Before Git, Linux developers used a proprietary system called BitKeeper for version control. However, conflicts arose between the BitKeeper team and the Linux community, leading Torvalds to develop an open-source alternative.

The goal was to create a tool that was:

  1. Fast
  2. Distributed, allowing developers to work offline
  3. Reliable, with strong support for non-linear development

Today, it's the most popular version control system, powering platforms like GitHub, GitLab, and Bitbucket, transforming how teams collaborate on code.

What is Git?

Git is a version control system VCS designed to track changes in source code and collaborate efficiently with others. It is widely used for software development due to its speed, flexibility, and support for non-linear workflows (e.g., branching and merging).

Install

You can donwload it from here install git

Check git version

git --version

Before we dive into the coding part of Git let u know some basic command of Linux

Basic Linux Commands

  1. To make a new folder or directory
mkdir <directory-name>
  1. Remove a directory
rmdir <directory-name>
  1. List file and directories
ls
  1. Create a new file
touch <file-name>
  1. Change directory
cd <directory>
  1. Present working directory
pwd
  1. View file contents
cat <file-name>

Git Command (CheatSheet)

Most Used

95% of the time you will find yourself writing only these commands of git.

  1. Initialize a new Git repository
git init
  1. Show the status of the working directory
git status
  1. Stage all changes in the current directory
git add .
  1. Commit staged changes with a message
git commit -m "message" 
  1. Push commits to a remote repository
git push
  1. View commit history
git log 
git log --oneline

Advanced Git

Some Advanced concpets of Git

1. What is .git/ Directory?

The .git directory is a hidden folder created when you initialize a Git repository using the git init command. It is the core of your Git project and contains all the necessary metadata and history for the repository

if you go into the .git (hidden folder) by running the following command

cd .git

Inside Git

If you want to read file in .git folder you can use cat

git cat

image-screenshot image-screenshot but the file is compressed so in this case, use

git cat-file -p d439a4edae8ac1ff3bf6cc4f78b12b80f8bc87c5

2. Complete Git Flow

Gitflow Diagram

3. Git diff

git diff