Git for Beginners: Basics and Essential Commands

Hello everyone! 👋
I wanted to share my notes in an easy-to-understand manner because I recently started learning Git. This tutorial is perfect if you're new to coding or want to learn how developers handle their code.
1️⃣ What is Git?
Git is a distributed version control system (DVCS) that helps developers track changes in their source code during software development.
A VCS is a tool or a system that helps developers manage changes to their source code over time. It allows developers to track modifications, revert to previous stages, and work collaboratively with others on the same codebase.
Git is specifically classified as a DVCS. In a DVCS, each developer has a complete copy of the entire project, including its full history. This is in contrast to the Centralized Version Control System (CVCS), where there is a single central repository.
Does that sound complicated? Let's analyze it:
Git uses version control to monitor changes made to your files over time.
Distributed projects don't rely on an internet connection; each developer has a copy of the project with its whole history.
In short:
2️⃣ Why Do Developers Use Git?
Git is used by developers because it facilitates safe, efficient, and well-organized code development, management, and collaboration. These are the primary causes. 👇
Track Code Changes
Git keeps track of all file modifications. You are constantly aware of what changes were made, who made changes, and when.
Go Back in Time (Version Control)
If something breaks, Git lets you restore older versions of your code easily.
Work in Teams Without Conflict
Multiple developers can work on the same project using branches, without overwriting each other’s work.
Experiment Safely
Want to try a new feature?
Create a branch and experiment without affecting the main code.
Offline Access
Git works locally. Do not need the internet to track changes or commit code.
Easy Collaboration with GitHub
Git easily integrates with websites such as GitHub to:
Share code
Review Changes
Manage open-source projects
Industry Standards
Git is used by:
Startups
Big tech companies
Open-source communities
Learning Git is almost mandatory for developers today.
In simple words:
3️⃣ Git Basics and Core Terminologies
⭐ Repository (Repo)
A repo is a project folder tracked by Git.
It contains files plus the full history of changes.
⭐ Working Directory
The place where your files actually live and you make changes.
⭐ Staging Area
Like a waiting room for files you want to include in your next commit.
⭐ Commit
A snapshot of your project at a moment in time
(with a message explaining what changed).
⭐ Branch
A separate line of development.
You can experiment safely without breaking the main code.
⭐ HEAD
Pointer to your current working branch/commit.
4️⃣ Essential Git Commands (With Simple Examples)
These are the most commonly used Git commands that every beginner should know.
1️⃣ git init Initialize a Repository
This command starts Git tracking in your project.
git init
📌 What it does:
Creates a hidden
.gitfolderTurns a normal folder into a Git repository
👉 Run this once per project.
2️⃣ git status Check Current State
Shows what’s happening inside your repository.
git status
📌 It tells you:
Which files are modified
Which files are staged
Which files are untracked
🧠 Think of it as:
“What’s going on in my project right now?”
3️⃣ git add Stage Files
Moves changes from the working directory to the staging area.
Add a single file:
git add index.html
Add all files:
git add .
📌 Staging means:
“I want this change in my next commit.”
4️⃣ git commit Save a Snapshot
Creates a permanent snapshot of staged changes.
git commit -m "Add initial project files"
📌 Best practice:
Write short, meaningful messages
Use present tense (add, fix, update).
5️⃣ git log View Commit History
Shows all commits made in the repository.
git log
Short and clean view:
git log --oneline
📌 Helpful to:
Track progress
Debug issues
Understand project history
⭐ More Useful Git Commands (Beginner Level)
🔹 git diff
Shows changes that are not yet staged.
git diff
🔹 git reset
Un-stage a file (without deleting changes):
git reset index.html
🔹 git branch
List branches:
git branch
Create a new branch:
git branch feature-login
🔹 git switch
Switch to another branch:
git switch feature-login
🔹 git checkout (Older but common)
git checkout feature-login
🔁 Typical Daily Git Workflow
Edit Code
↓
git status
↓
git add .
↓
git commit -m "Meaningful message"
↓
Repeat 🔄
👉🏻 Diagrams:
- Basic Workflow using Git

- Local Repository Structure

- Commit History Flow

📌 Diagram 1: Git File Flow
Working Directory → Staging Area → Repository
┌────────────────────┐
│ Working Directory │ (You edit files here)
└─────────┬──────────┘
│ git add
▼
┌────────────────────┐
│ Staging Area │ (Ready to commit)
└─────────┬──────────┘
│ git commit
▼
┌────────────────────┐
│ Repository │ (History safely stored)
└────────────────────┘
📌 Diagram 2: Local Git Repository Structure
Shows where things actually live
Your Project Folder
|
├── .git/ ← Hidden folder Git creates
│ ├─ commits
│ ├─ branches
│ ├─ configuration
│ └─ history
|
└── your files
├─ index.html
├─ app.js
└─ styles.css
👉 The .git folder is the brain of your repository.
📌 Diagram 3: Commit History Flow
(o) Initial commit
\
o ---- o ---- o ---- o
│ │
│ └─ (feature added)
│
(bug fix)
Or a cleaner linear one:
Commit A ──→ Commit B ──→ Commit C ──→ Commit D
"init" "ui added" "bug fix" "final"
📌 Diagram 4: Branching Example
main branch: A ── B ── C ── D ── E
\
feature branch: F ── G ── H
Merge time:
main: A ── B ── C ── D ── E ── M
▲
feature: F ── G ── H ──┘
📌 Diagram 5: Basic Git Workflow
1. Make changes → 2. Stage changes → 3. Commit
Edit files git add . git commit -m ""
Extended with command flow:
Write Code
↓
git status
↓
git add file.js (stage)
↓
git commit -m "message"
↓
git log (see history)

