Level 10 / Version Control

Git & GitHub Masterclass

Master the time-travel machine of software engineering. This guide moves beyond basic commands to help you understand the internal states, branch management, and how to rescue your work when things go wrong.

  • Mental Model First Understand Working Dir vs Staging vs Repo.
  • Disaster Recovery Learn reflog and reset to fix mistakes.
  • Team Workflow PRs, Merge vs Rebase, and Conflict resolution.
Now readingConcepts

The 4 States of Git

Git isn't just a backup tool; it's a state machine. Most confusion comes from not knowing which of these four "areas" your changes currently reside in.

1. Working Directory

Untracked or modified files on your disk. Git knows they changed but doesn't "own" them yet.

2. Staging Area (Index)

A middle ground. You've marked these changes to be included in the next snapshot.

3. Local Repository

The committed history on your machine. Your work is safe here locally.

4. Remote Repository

The shared truth (GitHub/GitLab). Where your team sees your work.

The Searchable Git Bible

0 rows
Command Impact Zone When to use it

"Oh no, I broke it" (Disaster Recovery)

Git is almost impossible to break permanently. Here is how to undo the most common "mistakes".

Undo the last commit (keep changes)

git reset --soft HEAD~1

Moves changes back to the Staging area. Perfect if you forgot a file or made a typo in the message.

Rescue "deleted" work

git reflog

Git's secret diary. It records every move you make, even if you delete a branch. Find the hash and git checkout [hash] to bring it back.

Interactive Rebase (Clean history)

git rebase -i HEAD~3

Squash 5 messy "wip" commits into one clean feature commit before pushing.

Interactive Git Flow

Click the commands to see how they move your files through the 4 states.

Workdir
Staging
Local Repo
Remote