Skip to main content

Git: A Time Machine for Your Code

beginner16 min readLesson 46 of 143

Version control explained from zero: repositories, commits, and the everyday add/commit/status rhythm.

Git records snapshots of your project so you can look back, undo, and collaborate. Without it, developers emailed folders named final-v3-REAL.zip. With it, every state of your project is one command away.

The repository

A repository ("repo") is a folder Git watches. Turn any project into a repo:

git init

This creates a hidden .git folder β€” the time machine itself. Your files do not change; Git just starts paying attention.

The three places your code lives

  1. Working directory β€” the files you edit
  2. Staging area β€” changes chosen for the next snapshot
  3. Repository history β€” the permanent snapshots ("commits")
git status          # what has changed? what is staged?
git add index.html  # stage one file
git add .           # stage everything changed
git commit -m "Add navigation bar"    # snapshot the staged changes

Commits are checkpoints, not backups

A commit is a named snapshot with a message explaining why. Good messages complete the sentence "This commit will…":

git commit -m "Fix broken link in the footer"     βœ“
git commit -m "stuff"                              βœ— future-you will hate this

Small, frequent commits turn big changes into a readable story β€” and give you dozens of restore points.

Looking back

git log --oneline   # the history, one line per commit

Made a mess before committing? git status tells you the state; the history keeps everything safe that you did commit. This course's own repo has dozens of commits β€” run git log --oneline on any real project and read it like a diary.

What you learned

  • git init starts the time machine
  • edit β†’ git status β†’ git add β†’ git commit -m
  • Commit messages explain why, in present tense
  • git log reads the history

Next: branches β€” experiment without breaking the main line.

Now practice

Git: A Time Machine for Your Code β€” PracticeHands-on practice for β€œGit: A Time Machine for Your Code”: apply what you just learned in git-version-control.1 challenge Β· Β· ~10 minGit Workflow DrillsType the commands you'll use every day: stage and commit, branch and merge, recover from a mistake.2 challenges Β· Β· ~12 min