Git: A Time Machine for Your Code
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
- Working directory β the files you edit
- Staging area β changes chosen for the next snapshot
- 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 initstarts the time machine- edit β
git statusβgit addβgit commit -m - Commit messages explain why, in present tense
git logreads the history
Next: branches β experiment without breaking the main line.