Skip to main content

Command Palette

Search for a command to run...

πŸš€ Git for Beginners: Basics and Essential Commands

Updated
β€’3 min readβ€’View as Markdown
πŸš€ Git for Beginners: Basics and Essential Commands

Git is one of the most important tools every developer must learn.
If you’re starting your web development journey, understanding Git early will save you hours of confusion later.

This guide explains Git in simple terms, with practical examples and visual diagrams.

What is Git?

Git is a Distributed Version Control System (DVCS).

In simple words:

  • Git tracks changes in your code

  • Git lets you go back in time

  • Git helps multiple developers work together safely

Think of Git as a history book of your project πŸ“˜
Every change you save becomes a new page.

Why is Git Used?

Git is used to:

  • βœ… Track file changes

  • βœ… Collaborate with teams

  • βœ… Experiment without fear

  • βœ… Recover from mistakes

  • βœ… Maintain clean project history

Without Git, managing large projects would be chaos πŸ˜΅β€πŸ’«

Git Basics & Core Terminologies

Let’s understand the core building blocks of Git.

πŸ“ Repository (Repo)

A repository is a folder that Git tracks.

git init

This command:

  • Creates a .git folder

  • Starts version tracking

πŸ§‘β€πŸ’» Working Directory

This is where you:

  • Write code

  • Edit files

  • Delete or add files

Simply your project folder on your system.

πŸ“¦ Staging Area

Before saving changes permanently, Git lets you choose what to save.

git add index.html

πŸ“Œ This moves files to the staging area.

πŸ“Έ Commit

A commit is a snapshot of your project at a moment in time.

git commit -m "Add homepage layout"

Each commit contains:

  • A unique hash

  • Commit message

  • Author

  • Timestamp

🌿 Branch

A branch allows you to work independently.

  • main β†’ stable code

  • feature branches β†’ new ideas

git branch feature-login

🎯 HEAD

HEAD is a pointer that shows:

Where you currently are in the commit history

Usually, it points to the latest commit.

Common Git Commands

πŸ”Ή Initialize Repository

git init

πŸ”Ή Check Status

git status

Shows:

  • Untracked files

  • Modified files

  • Staged files

πŸ”Ή Add Files to Staging

git add file.js
git add .

πŸ”Ή Commit Changes

git commit -m "Initial commit"

πŸ”Ή View Commit History

git log

πŸ”Ή View Differences

git diff
git diff --staged

πŸ”Ή Branch Commands

git branch
git checkout branch-name

πŸ”„ Basic Git Workflow (From Scratch)

πŸ§ͺ Real-World Developer Flow

mkdir my-project
cd my-project
git init
touch index.html
git add .
git commit -m "Initial project setup"

βœ”οΈ Your project is now under Git version control.

πŸ“Š Diagrams (Beginner Friendly)

πŸ” Git File Flow

Working Directory
        ↓
  Staging Area
        ↓
   Repository

πŸ—‚οΈ Local Repository Structure

my-project/
β”‚
β”œβ”€β”€ .git/
β”‚   └── (Git metadata)
β”‚
β”œβ”€β”€ index.html
β”œβ”€β”€ style.css
└── script.js

🧾 Commit History Flow

Commit A ──→ Commit B ──→ Commit C (HEAD)

🌱 Final Thoughts

Git may feel confusing at first, but:

Every professional developer uses Git daily.

Start small:

  • Practice basic commands

  • Make frequent commits

  • Don’t fear mistakes β€” Git is your safety net πŸ›Ÿ

Once Git feels comfortable, learning GitHub, collaboration, and DevOps becomes much easier.

More from this blog

mnraza

22 posts