Lesson 5 of 12 · Learn to drive
Git is your undo button. Learn it before the AI deletes something.
Turn the scratch project into a Git repository, take snapshots, break something on purpose, and go back. Then back it all up to GitHub.
At some point the AI is going to change something you did not want changed, and it will not always be able to put it back. Git is what makes that a thirty-second problem instead of a lost afternoon. You will practice it on the scratch project from Lesson 4, break the project on purpose, and watch it come back. If you want the long version of why this matters, the AI deleted my code is the story of what happens without it.
Everything in this lesson is done by asking Claude Code. You do not need to learn Git commands. You need to learn the habit and the words.
The idea in one paragraph
Git keeps a history of your project as a series of snapshots called commits. Each commit has a short message saying what changed. At any time you can look at the list of commits, see exactly what a commit changed, and go back to any snapshot. GitHub is a website that stores a copy of that history, so a stolen laptop or a bad afternoon does not lose the project. That is all you need to know.
Step 1: Turn the scratch folder into a repository
In a terminal:
cd ~/projects/scratch
claude
Shift + Tab to manual mode. Then:
Turn this folder into a Git repository. Add a sensible .gitignore for a plain HTML project. Then make the first commit with the message "Good Boy Walks landing page". Tell me what you did in plain English.
Approve what it proposes. When it is done, ask:
Show me the commit history.
You should see one commit with your message. That is your first snapshot.
Step 2: Change something and commit again
Change the tagline in the header to "Happy dogs, tired dogs." Then commit with the message "Update tagline".
Look at the page in your browser (refresh). Then:
Show me the commit history.
Two commits. Now you have a before and an after.
Step 3: Break it on purpose
This is the part people skip, and it is the part that makes the habit stick.
Delete the entire services section from the page and commit with the message "Oops".
Refresh the browser. The services are gone. Now, imagine that was the AI misunderstanding a request on the real app. Ask:
That was a mistake. Undo the last commit and put the page back exactly how it was before it, keeping the history intact. Explain what you did.
Refresh. The services are back. Ask for the history one more time: you should see the “Oops” commit and a new commit that reverses it. Git does not erase history; it adds a snapshot that undoes the bad one. That is why it is safe.
What just happened, in words you can reuse. “Undo the last commit, keeping history” is a revert. It is safe. “Show me what changed in the last commit” is a diff. “Throw away every change since the last commit” is a reset, and it really does throw the changes away; you will use it on purpose later in the course, always with that exact wording so there is no confusion. You can say any of these to Claude Code in plain English and it will know what you mean.
Step 4: Back it up to GitHub
GitHub is where your history lives online. Later, it is also how the app gets to the internet. The easiest way to get started is GitHub Desktop, a free app that handles the first upload for you.
- Go to github.com and create a free account if you do not have one. Pick a username you would be fine with a client seeing.
- Download GitHub Desktop, install it, and sign in with that account.
- In GitHub Desktop: File → Add Local Repository, click Choose…, pick the
scratchfolder insideprojectsin your home folder (on Windows that isC:\Users\yourname\projects\scratch), and click Add Repository. - Click Publish repository. Keep “Keep this code private” ticked. Click Publish repository in the dialog.
Go to github.com in your browser. Your repository is there, with all four commits. That is your backup.
Step 5: Let the terminal push too
From now on you will want Claude Code to push for you after each commit, so the backup is always current. For that, the terminal needs to be signed in to GitHub as well. The reliable way on both Mac and Windows is GitHub’s command-line tool.
Mac: go to cli.github.com, download the macOS installer (the .pkg), and run it.
Windows (PowerShell):
winget install GitHub.cli
Close the terminal, open a new one, and run:
gh auth login
It asks a few questions. Answer: GitHub.com, HTTPS, Yes to “Authenticate Git with your GitHub credentials,” and Login with a web browser. It shows a short code; press Enter, paste the code into the browser page that opens, and approve. Back in the terminal it says you are logged in.
Test it. Back in Claude Code:
Change the owner's name from Maria to Marisol, commit with the message "Rename owner", and push to GitHub.
Refresh the repository page on github.com. Five commits.
The habit
Here is the rule for every lesson from now on:
When something works, commit it. Before you ask for anything risky, commit it. When the AI finishes a task and you have checked it, commit it.
The prompt is always the same shape: “Commit this with the message … and push.” You will write that sentence dozens of times in this course. It takes five seconds and it is the cheapest insurance in software.
Two more things people learn the hard way:
- Never commit secrets. Passwords, API keys, anything in a file called
.env. Lesson 8 shows how the.gitignorefile keeps them out. If you are ever unsure, ask: “Is there anything in this commit that should not be public?” - Commit before you loosen permissions. If you switch Claude Code to auto mode so it stops asking, do it right after a commit, never in the middle of a half-working change.
Check your work
- The history shows at least five commits, including “Oops” and the commit that reversed it.
- The services section is back on the page.
- The repository is visible on github.com under your account, marked Private.
gh auth loginsaid you are logged in, and “commit with the message X and push” works from Claude Code.
If something went wrong
Claude Code says Git is not configured or asks for a name and email. Go back to Lesson 2, Step 3 and run the two git config commands.
GitHub Desktop says the folder is not a repository. Step 1 did not finish. Ask Claude Code: “Is this folder a Git repository? If not, make it one and commit everything.”
The push asks for a username and password in the terminal, or hangs. Press Ctrl + C. Step 5 did not finish; run gh auth login again and make sure you answered Yes to authenticating Git. Until it works, you can always push by clicking Push origin in GitHub Desktop after Claude commits.
Windows: winget is not recognized. Download the Windows installer from cli.github.com instead, run it, open a new PowerShell, and continue from gh auth login.
I did the revert and now the page is wrong in a different way. Ask: “Show me the last three commits and what each one changed.” Then: “Go back to the state after the commit called ‘Update tagline’, keeping the history.” If it proposes a “reset” or says it will discard commits, say no and ask it to revert instead.
Next
The tools are installed and you know how to drive. Lesson 6 starts the real project: a Next.js app that runs on your laptop.
Did this lesson not go to plan?
A CTO can help you starting today.
Screenshot the error, note which step you were on, and request a call. Every member starts with a call: bring what you built and where it stopped, and that is where we work out whether we can help and what to do first. No card. No sales deck.
Request a call with your CTO