Git for Beginners: From “What Is This?” to Your First Commit

Search for a command to run...

No comments yet. Be the first to comment.
Comeing soon

In the previous blog of this JavaScript series, we explored JavaScript Operators: The Basics You Need to Know and learned how operators help us perform calculations, comparisons, and logical checks. B

In the previous blog of this JavaScript series, we learned about Variables and Data Types — how JavaScript stores information. Now the next question is: How do we actually work with those values? Th

If you're starting your JavaScript journey, one of the first concepts you'll encounter is Variables and Data Types. They are the foundation of everything in programming — from storing a user's name to

JavaScript Promises are one of the most misunderstood yet essential features in modern JavaScript development. Most articles explain the syntax. Very few explain: Why Promises exist How they actuall

Subhrangsu
18 posts
Have you ever worked on a project, made a mistake, and wished you could just “Control + Z” your entire life back to two hours ago? Or collaborated on a group project where everyone emailed files named:
final_v2_REALLY_FINAL.docx
That frustration is exactly why Git exists.
Git is a Version Control System (VCS).
Think of it as a high-tech “Save Game” system for your code. Instead of overwriting files, Git records snapshots of your project over time.
This allows you to:
📌 Git is the tool. GitHub / GitLab are places where Git repositories are stored remotely.
Git solves real developer problems:
Before touching commands, you need Git’s mental model.
A repository is a project tracked by Git.
When you run:
git init
Git creates a hidden folder:
.git/
📌 This .git folder is the brain of Git
Everything lives here: commits, branches, history, and HEAD.
This is where you:
Example:
index.html
app.js
style.css
⚠️ These files are not tracked automatically.
Git does not commit directly from your files.
Instead, it uses a middle layer:
Working Directory
↓ git add
Staging Area
↓ git commit
Repository (.git)
Why does the staging area exist?
A commit is a snapshot of your project at a moment in time.
Each commit:
Think of it as:
🎮 “Save checkpoint with a message”
Example history:
commit 1 → hash-01
commit 2 → hash-02
commit 3 → hash-03
A hash is used to:
HEAD points to the current branch, which points to the latest commit.
commit-01 ← commit-02 ← commit-03
↑
HEAD
Every Git workflow follows this exact path:
Once this clicks, Git becomes easy.
git init
Initializes a Git repository.
To see the hidden folder:
ls -a
git status
Shows:
git add filename
Or add everything:
git add .
Moves files:
Working Directory → Staging Area
git commit -m "Initial commit"
This:
git log
Short version:
git log --oneline
Example:
a1b2c3d Added feature
b2c3d4e Fixed bug
c3d4e5f Initial commit
git diff
Compare commits:
git diff <hash1> <hash2>
Commit-01 ← Commit-02 ← Commit-03 ← Commit-04
↑
HEAD
Each commit stores:
This is why Git is fast and reliable.
git cat-fileGit stores everything (commits, files, folders) as objects inside the .git directory.
The command that lets us inspect these objects is:
git cat-file -p <commit-hash>
git cat-file -p 2b3f9a
(Git allows short hashes as long as they uniquely identify the object.)
Output looks like:
tree a3f5c9...
parent 91ab2d...
author John Doe <john@email.com>
committer John Doe <john@email.com>
Initial project setup
📌 Git commits don’t store diffs — they store snapshots + references.
A branch is just a pointer to a commit.
main: A → B → C → D
\
feature: E → F
HEAD switches between branches.
git branch
Check HEAD directly:
cat .git/HEAD
git revert <hash>
Creates a new commit that undoes a previous one (best for shared projects).
git reset --hard <hash>
What it does:
Use only when you know what you’re doing.
git initindex.htmlgit statusgit add index.htmlgit commit -m "Initial project setup"git log --oneline[ Working Directory ]
↓ git add
[ Staging Area ]
↓ git commit
[ Repository (.git) ]
This is the heart of Git.
git init
ls -a
git status
git add <file>
git add .
git commit -m "message"
git log
git log --oneline
git diff
git diff <hash1> <hash2>
git cat-file -p <hash>
cat .git/HEAD
git branch
git revert <hash>
git reset --hard <hash>
If this cheatsheet makes sense — you understand real Git, not just commands.
Git feels intimidating at first because of:
But once you understand:
Working Directory → Staging Area → Repository → HEAD
Git stops being scary and starts feeling powerful.
You’re no longer afraid of mistakes — because Git remembers everything.