Skip to main content

Command Palette

Search for a command to run...

🚀 Day 22 – Introduction to Git: Your First Repository

Updated
5 min read

Git is the backbone of modern DevOps.

Every CI/CD pipeline, every collaboration workflow, every production deployment — everything depends on version control.

Before learning advanced Git, we must understand the basics deeply.

Today we will:

  • Understand what Git is

  • Create our first Git repository

  • Make real commits

  • Build a clean commit history

  • Understand how Git actually works internally

Let’s begin.


🧠 What is Git?

Git is a Version Control System (VCS).

That means:

  • It tracks changes in files

  • It remembers every version

  • You can go back in time

  • You can collaborate safely

  • You can see who changed what

Think of Git as:

A time machine for your code.


🏗️ Core Git Architecture (Very Important)

Git works in 3 areas:

  1. Working Directory → Where you edit files

  2. Staging Area → Where you prepare changes

  3. Repository → Where commits are permanently saved

Understanding this is 50% of Git.


✅ Task 1 – Install and Configure Git


1️⃣ Check if Git is Installed

git --version

What this does:

  • Shows the installed Git version

  • Confirms Git is installed

Example Output:

git version 2.53.0.windows.1

If you see this → Git is ready.


2️⃣ Set Your Identity

Git needs your name and email to attach to commits.

git config --global user.name "Divyat Agrawal"
git config --global user.email "divyatagrawal01@gmail.com"

What --global means:

It sets configuration for all repositories on your system.


3️⃣ Verify Configuration

git config --list

This shows:

  • Your name

  • Your email

  • Other Git settings


✅ Task 2 – Create Your First Repository


1️⃣ Create Project Folder

mkdir devops-git-practice
cd devops-git-practice
  • mkdir → creates folder

  • cd → enters folder


2️⃣ Initialize Git

git init

Output:

Initialized empty Git repository

What this does:

  • Creates hidden .git folder

  • Turns normal folder into Git repository


3️⃣ Check Status

git status

Example Output:

On branch master
No commits yet
nothing to commit

What git status shows:

  • Current branch

  • Modified files

  • Staged files

  • Untracked files

git status is your best friend in Git.


4️⃣ Explore .git Folder

ls -a

You’ll see .git.

Inside it:

HEAD
config
objects
refs
hooks

What .git does:

  • Stores commit history

  • Stores branch info

  • Stores configuration

  • Stores everything Git needs

⚠️ If you delete .git, all history is gone.


✅ Task 3 – Create Git Commands Reference


Create File

touch git-commands.md

Now check:

git status

You’ll see:

Untracked files:
  git-commands.md

What “Untracked” means:

Git sees the file but is not tracking it yet.


✅ Task 4 – Stage and Commit


1️⃣ Stage File

git add git-commands.md

What this does:

  • Moves file to staging area

  • Prepares it for commit

  • Takes snapshot of current version

Think of it like:

Selecting changes you want to save.


2️⃣ Check What’s Staged

git status

You’ll see:

Changes to be committed

3️⃣ Commit

git commit -m "Add git-commands.md initial file"

What commit does:

  • Creates permanent snapshot

  • Assigns unique commit ID

  • Saves it inside .git

Each commit:

  • Has a hash

  • Has author

  • Has date

  • Has message


4️⃣ View History

git log

Compact view:

git log --oneline

Example:

3d60d95 Add basic workflow commands
f01fed8 add setup and version commands
9d7e6b7 adding commands of git

✅ Task 5 – Build Commit History

Edit file.

Then check:

git diff

What git diff does:

Shows line-by-line changes.

  • + added lines

  • - removed lines

Then:

git add .
git commit -m "Add basic workflow commands"

Repeat 3 times to build history.

Why?

Because good developers:

  • Make small commits

  • Write clear messages

  • Keep history clean


✅ Task 6 – Understanding Git Workflow


1️⃣ Difference Between git add and git commit

  • git add → Moves changes to staging area

  • git commit → Saves staged changes permanently


2️⃣ What Does Staging Area Do?

It allows you to:

  • Select specific changes

  • Commit only what you want

Without staging, Git would commit everything automatically — which is risky.


3️⃣ What Does git log Show?

It shows:

  • Commit ID

  • Author

  • Date

  • Commit message

It shows the history of the project.


4️⃣ What is .git Folder?

It is:

  • Git’s internal database

  • Stores all commits

  • Stores branches

  • Stores configuration

Deleting it removes version control completely.


5️⃣ Difference Between Areas

Area

Meaning

Working Directory

Where you edit files

Staging Area

Where you prepare changes

Repository

Where commits are saved


🎯 Final Git Workflow (Simple Version)

  1. Edit file (Working Directory)

  2. git add (Move to Staging)

  3. git commit (Save permanently)

  4. git log (See history)

Repeat.