Git: saves like in a game
Lesson 7 of 26 in the course “Vibe coding”. Free, with animations and a quiz.
Saves like in a game
In a game you save before the boss so you don't have to replay everything. Git does the same for a project. Git is a program that remembers every version of your files. Example: you and AI are building a site for your shooter squad. The figure shows the whole path: skeleton (an empty page template), menu, login form. Each circle is a separate save you can go back to.
A commit is a save point
A commit is a save in Git: a snapshot of the whole project at one moment. Each commit gets a short message about what changed. The rule is simple: what changed, in a few words. “login form” is clear right away. “fix”, “asdf” or “all good” will tell you nothing a week later. The labels in the figure are a good example: you read the history like a to-do list.
Broke it? Roll back
You asked AI to “make the design brighter” and all the styles fell apart: buttons crawled over the text. That's the red commit “broke styles”. Without Git you'd have to remember how it looked before. With Git you open the history, the list of all commits, and roll back: you return the project to the “login form” commit where everything worked. That's the “rollback” arrow in the figure.
Commit after every step
The basics: a working step is done, commit right away. Built the skeleton, checked it, saved. Added the menu, checked it, saved. It matters most before a big request to AI like “redo the whole design”. Then whatever happens, you lose one step at most, not a whole evening of work. AI editors and agents can make commits themselves: just ask.
Diff: what exactly changed
A diff is a line-by-line comparison of two versions. Added lines are highlighted green, removed ones red. Example: the “+12 −3” chip in the figure means the commit added 12 lines of code and removed 3. Look at the diff before you commit. If you asked to change the color of one button and the AI rewrote, say, hundreds of lines, that's a reason to ask it why.
Check yourself
- What is a commit in Git?
Correct answer: A save of the project with a short message. A commit is a snapshot of the project at one moment plus a message about what changed. You can always go back to it. - When is it especially important to commit?
Correct answer: Before a big request to AI, while everything works. A commit before a big change gives you a working point to roll back to. A commit after things break just saves the broken version. - In a diff a line is highlighted red. What does it mean?
Correct answer: This line was removed. In a diff green means “added” and red means “removed”. Red here is not about a bug.