🛠️ Build Your First Mini App with Claude Code · Week 1: From Zero to Your First Live Web Page

Minimal git for Beginners: Insurance for AI-Written Code (Claude Code)

Breaking things isn't scary. Not being able to go back is

一句话先懂 · TL;DR

No commands to memorize. Treat git as save points: every time the AI finishes a working version, save one; if something breaks, go back with one sentence. Learn 3 commands and 1 habit, and AI coding never leaves you stuck with a broken project again.

A Real Lesson

A beginner who couldn't code and took on freelance work with AI looked back on his first project: whenever there was a bug he'd just say "something's wrong here, fix it". The AI fixed one spot and broke another. He didn't know git, and didn't know code could be returned to a previous version, so all he could do was keep asking the AI to fix, and it got messier every round.

The first habit he learned afterwards: every time you finish an important feature, save a version that runs correctly.

🔆git is the save point in a video game. Save before the boss fight; if you die, reload instead of pushing on at half health.

Three Commands, One Habit

You can have Claude Code type these commands for you, but you should know what they mean:

git init                      # 在项目里开启存档功能,只做一次
git add -A && git commit -m "待办清单:添加/完成/本地保存 三项验收通过"
                              # 存一档,引号里写这一档做到了什么
git log --oneline             # 看所有存档

There's only one habit: when it passes acceptance, save. Not once a day, not after everything is done, but after every single change that passes. That way every save is a "working" one, and a rollback always lands on a working state.

💡Put this habit in CLAUDE.md: "After each change that passes acceptance, make a git commit with a message saying what was done". Then it will save for you automatically.

When It Breaks: Reload the Save, Don't Force a Fix

The AI adds categories and breaks "mark as done". You ask it to fix that, and now "delete" is broken. At this point, stop. Don't ask for a third round.

Say to it:

「分类功能改坏了原有功能。放弃这次改动,把代码回到上一次提交(删除按钮验收通过那一档)。回去之后我们重新用 Plan 模式做分类。」

It will use git checkout or git restore to bring the files back to that save. All you lose is this one failed attempt, not the whole afternoon.

自测 · 学完检查一下

想真正动手做题、记进度、攒连胜?到互动课里练。

For a beginner coding with AI, what is git's main value?

答案:Save a checkpoint for every working version, so if something breaks you can go back with one sentence

Sharing and uploading is another use of git, but what matters most to you right now is "undoable". It doesn't find bugs and it doesn't speed up the AI. It only guarantees you always have a way back.

Which of these is the best moment to save a checkpoint?

答案:After the "delete button" is built and passes acceptance, before starting on "categories"

The standard for a save is "this version works". Saving by the clock may save a broken version. Saving only at the end means no way back in the middle. Saving before checking means you don't know whether you saved a good or bad one.

True or false: a commit message of "update", "changes", or "fix" is enough, since you know what you changed anyway.

答案:False

When rolling back, you need to find "the last working one" in a list of saves, and "update" or "changes" makes them indistinguishable. Write "delete button passed acceptance" and you can pick the one to return to at a glance.

The AI has spent two rounds fixing a bug and it's getting worse each time, while the previous save passed acceptance. What's the biggest time-saver right now?

答案:Have it go back to the previous save, then redo the feature in plan mode

Two rounds of getting worse means it no longer knows what it changed, and a third round will most likely be worse still. Returning to the working save loses the least. Going back through plan mode is so the approach gets talked through first this time. Digging through code yourself or starting over both cost far more than reloading the save.

Fang has never saved a checkpoint, and now a feature is broken. Can he go back to "yesterday's working version" with one sentence?

答案:No. With no save there's no version to return to. All he can do is have the AI keep fixing or rebuild

git only records the saves you commit on purpose; it doesn't save for you automatically. The AI starts a new conversation on every launch and doesn't remember yesterday's code. The browser caches what the page looked like, not the source file. That's why "save when it passes" has to become a habit.

想边练边学,而不只是读?

到互动课里答题、记进度、攒连胜——游客即可试学,无需注册。

进入互动课程 →

Learn something new — don't miss updates

New courses, features and learning tips. Occasional emails, unsubscribe anytime.