Git — the undo button for everything you write
By the end of this lesson you will have your course folder under git, two commits in its history, and one diff you have read line by line.
Build Your First Tool lesson 1 mentions "git history" as though you already know what that is. This is where you find out, and it takes twenty minutes.
What problem it solves
You change something, it breaks, and you cannot remember what it looked like before. Every beginner solves this with index-final-FINAL-v2.js, and that solution collapses within a week.
Git records snapshots you choose, with a note saying why. You can go back to any of them, and you can see exactly what changed between two.
Four commands, in the order you use them
git init start recording this folder (once)
git status what has changed since the last snapshot
git add . choose everything changed for the next snapshot
git commit -m "why" take the snapshot
Then git log lists them and git diff shows what changed. That is a working knowledge of git for this entire track.
The message is the point
git commit -m "stuff" is a snapshot you cannot find later. -m "fetch prices before rendering, so the table is never empty on load" is one you can.
The message is written for you in three months, who will not remember. This is the same reader the whole build track keeps coming back to, and it is worth writing for them from your first commit.
Commit small, and often
One idea per commit. Not "a day's work" — a change you can describe in one sentence.
This matters much more with an assistant than without one, and Build Your First Tool explains why in detail: when a generated change breaks something, small commits let you find and undo exactly the part that broke. A day of generated work in one commit is a day you either keep entirely or lose entirely.
.gitignore, briefly
Some things must never be recorded: secrets, and anything the machine can regenerate. A file called .gitignore lists them. You will meet a real one in Build Your First Tool, where the line that matters holds your API key. For now just know that "git records everything in the folder" has deliberate exceptions.
Try it now
In your course folder, where SETUP.md and idea.txt now sit (no other file is needed): git init, then git branch -m main, git add ., git commit -m "first commit". The git branch -m main line names your main line of history main: depending on how git was installed, a fresh repository calls it master, and every later lesson (and most of the internet) says main. After the first commit, git branch shows the name; before it, git branch prints nothing, because a branch with no commits is not listed yet. Then change SETUP.md: add a line saying which terminal you use. Run git diff and read what it shows you. Those coloured + and - lines are what "reading a diff" means, and Build Your First Tool spends a whole unit on the habit.
The first time you commit, git may ask who you are; it prints two git config --global commands that tell it, and you run them once with your own name and an email address. That email is written into every commit, and it is public if the repository ever goes to GitHub (lesson 20 does that). If you would rather keep your real address private, GitHub gives every account a private one of the form 12345+yourname@users.noreply.github.com under Settings, Emails; use that instead.
The prompt
Run git diff after your change, then paste what it printed into your chat assistant:
I am learning git. Below is what git diff printed after I changed one
file. Explain, one sentence per line, what each line starting with +
or - means, and what the line starting with @@ tells me. Do not
suggest any git commands.
[paste the output of git diff]
A good answer says the - line was there before and is gone, the + line is new, and the @@ line says where in the file the change sits.
Check it yourself
git log --onelinelists one line: a short id and your message.- After your change,
git statusnamesSETUP.mdas modified. git diffshows only the line you added, marked+.- After the checkpoint commit below,
git statusreports nothing to commit andgit log --onelinelists two lines, the newest on top.
Compare with ours
Our history after this lesson
$ git log --oneline
3f2c1aa Record which terminal I use, for the day a command behaves differently
9b7e042 first commit
The first message says nothing; the second says what changed and why. Read both in three months and only one helps.
Checkpoint
git status # only the files you expect, and no .env*
git add -A
git commit -m "Record which terminal I use, for the day a command behaves differently"
git status first: it should list only the files you meant to change. Every checkpoint from here on has this shape. git add -A is git add . for the whole repository, wherever in it you stand. And .env is how the names of files that hold keys begin; you will make your first one in unit 5, and none should ever be listed here. Then answer this lesson's questions.