Skip to main content

Command Palette

Search for a command to run...

Git Explained for Beginners: Concepts, Commands, and Workflow

Understand Git Step by Step: Repositories, Commits, Branches, and Workflow

Published
4 min read
Git Explained for Beginners: Concepts, Commands, and Workflow

What Is Git?

Git is a Distributed Version Control System (DVCS).

In simple terms, Git helps you track changes in your code over time.

Think of Git like Google Docs for code.

When you write code, you constantly:

  • Add new lines

  • Remove old ones

  • Break things accidentally

Without Git, once you save over a file, the old version is gone.

Git prevents that.

Git keeps a full timeline of your project.
So you can:

  • Go back to an older version

  • See what changed and when

  • Fix mistakes without fear

Because of Git:

  • No pendrives

  • No “final_final_last” folders

  • No confusion about which version is correct


Why Is Git Used?

Life Before Git (The Pendrive Problem)

Imagine writing an assignment.

You copy it to a pendrive and give it to your friend to improve it.
Your friend edits it and gives it back.

Now ask yourself:

  • What exactly did they change?

  • What if they deleted something important?

  • What if both of you edited the same paragraph?

This is not a coding problem.
It’s a version problem.

Why Git Exists

Git solves this by acting like a time machine + security camera for your code.

  • Time machine → go back to any version

  • Security camera → see who changed what and why

That’s why Git is used in every serious software project.


Git vs GitHub (Very Common Confusion)

Git and GitHub are not the same thing.

Think of it this way:

  • Git is the camera

  • GitHub is the cloud storage where recordings are saved

Git

  • Runs on your computer

  • Tracks changes locally

  • Works even without internet

GitHub

  • Lives online

  • Stores Git repositories

  • Enables collaboration

You can use Git alone.
GitHub becomes necessary when you want teamwork.


Git Basics and Core Terminologies

Repository (Repo)

A repository is just a folder that Git watches.

Analogy:
A repo is like a project file where all versions of your work are stored.

When you run:

git init

Git starts tracking that folder.


Working Directory

This is where you actually write code.

Analogy:
Your working directory is like a rough notebook.

You scribble, erase, and experiment here.

Nothing is saved yet.


Staging Area

The staging area is a selection tray.

Analogy:
Imagine packing a parcel.

You don’t throw everything into the box.
You choose what should go inside.

git add is you saying:

“Pack these changes for delivery.”


Commit

A commit is a sealed parcel.

Analogy:
Once you seal and label a parcel, its contents can’t change.

A commit:

  • Freezes selected changes

  • Stores them permanently

  • Adds a message explaining why


HEAD

HEAD tells Git where you currently are.

Analogy:
HEAD is your bookmark in a book.

When you move to another page (commit or branch), the bookmark moves too.


Branch

A branch is a parallel timeline.

Analogy:
Imagine writing a story.

You copy chapter 3 and try a different ending—without ruining the original story.

That’s a branch.


Common Git Commands (With Meaning)

Initialize Git

git init

Creates a repository and a hidden .git folder.


Check Status

git status

Analogy:
This is like checking a checklist before submission.

It tells you:

  • What changed

  • What’s staged

  • What’s ignored


Stage Changes

git add .

Selects changes for the next commit.

Think of this as choosing files to include in a save point.


Commit Changes

git commit -m "Fix login validation"

This is the actual save.

A permanent checkpoint.


View History

git log

Analogy:
This is the timeline view of your project.


See Differences

git diff

Shows what changed but isn’t saved yet.


Undo Safely

git revert <commit>

Analogy:
Instead of erasing history, Git adds a correction note.

Safe when working with others.


A Simple Git Workflow

  1. Write code (Working Directory)

  2. Select changes (git add)

  3. Save snapshot (git commit)

  4. Repeat

Analogy:
Work → Pack → Seal → Repeat

This loop is Git.


What Does a Local Git Repository Look Like?

When Git is initialized, a hidden .git folder appears.

It contains:

  • Commit history

  • Branch info

  • HEAD pointer

  • Metadata

Your project files stay clean and normal.


Final Thoughts

Git is not about remembering commands.

Git is about:

  • Not being afraid of making mistakes

  • Trying new things without worry

  • Knowing you can always go back

When you think of Git as a time machine for your code, it becomes easy to understand.