DEV Community

Sreekar Reddy
Sreekar Reddy

Posted on • Originally published at sreekarreddy.com

🌳 Git Explained Like You're 5

A time machine for your code

Day 26 of 149

πŸ‘‰ Full deep-dive with code examples


The Time Machine

Imagine writing an essay and being able to:

  • Save a snapshot every few minutes
  • Go back to any previous version
  • See exactly what changed between versions
  • Try something risky and undo if it breaks

Git is a time machine for your code!


How It Works

You make "commits" - snapshots of your code at a moment in time.

Commit 1: "Started project"
Commit 2: "Added login page"
Commit 3: "Fixed bug in login"
Commit 4: "Added dashboard" ← You are here
Enter fullscreen mode Exit fullscreen mode

Messed up? Go back to Commit 3!


Key Commands

Command What it does
git init Start tracking a project
git add Stage files to save
git commit Save a snapshot
git log See history
git checkout Go back in time

Branches

Work on features without breaking the main code:

main:    ●——●——●——●
              \
feature:       ●——●——●
Enter fullscreen mode Exit fullscreen mode

When feature is ready, merge it back!


In One Sentence

Git saves snapshots of your code so you can go back in time, experiment safely, and collaborate with others.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

Top comments (0)