Git basics
5 minGit saves a snapshot of your project each time you commit, so a change that breaks the page can be undone with one command. You'll make a commit here, then undo it.
Lesson video
Tastebud · 5:10 · Captions on screen
Commit every small change that works, and Git keeps a snapshot you can go back to.
- Why. A file only holds what you saved last. When a change breaks the page, you need the version that worked, and a commit kept a complete copy of it.
- Real example. Edit your nav and VS Code's Source Control view lists styles.css with an M, for modified. Press the plus to stage it, type a message, then Commit. (VS Code, Nov 2026)
- When to break it. Some files should stay out of the history. npm install rebuilds the node_modules folder from your package file, so list it in .gitignore and Git skips it.
- Common mistake. One commit at the end of the day called 'update'. When the nav breaks, you can only undo the whole day, and the message can't say which change did it.
Our take. Commit before you let an AI coding tool touch your files. Claude Code's own undo, /rewind, skips any file only its shell commands changed. A commit made first covers every file.
A repository keeps one folder and its history
Copies like portfolio-final-2 keep old work but lose the reason for each change. A Git repository is your project folder plus its history: one set of files, and a message on every snapshot.
- portfolio-final, portfolio-final-2, portfolio-REAL
- Which copy has the new nav? Open each one
- Every copy repeats every file
- One portfolio folder and its history
- Each message says what changed
- git log lists them, newest first
Stage a change, then commit it
Staging means choosing which changes go into the next snapshot, so one commit holds one idea. The commit saves what's staged, with your message. Keep the message's first line to 50 characters or fewer.
A change passes through staging on its way into the history
- You to Project folder: Edit styles.css. git status now lists styles.css as modified.
- Project folder to Staging area: git add styles.css. Staging picks what goes into the next snapshot. Changed two files but only one is ready? Stage just that one.
- Staging area to History: git commit -m "Make nav links bigger". The staged changes are saved as one snapshot, with your message and a short id.
- History to You: git log --oneline. Lists the history, newest first, one commit per line.
Write the message as what the change does
A good message finishes the sentence 'This commit will...'. Next week, when something breaks, you'll scan these lines for the cause, and one idea per commit lets you undo that idea alone.
A message that names the change leads straight to the fix
- The nav breaks on phones. It's a week later, and you need the commit that caused it.
- Scan git log --oneline. One line per commit, newest first. The first line of each message is all you see.
- 'Make nav links bigger' stands out. It names the change in under 50 characters, so the likely cause is plain. A line that says 'update' would tell you nothing.
- Revert just that commit. One idea per commit means the undo takes out only the nav. A commit called 'fixed some stuff in nav and footer and the hero' would take all three out.
Try it
Commit a change, then undo it
You made the nav links bigger in styles.css, and the page looks right on your laptop. Save that snapshot. An hour later you see the nav wraps onto two lines on a phone, so undo it. Type each command as you would in the terminal.
- Stages styles.css (a dot stages every change) (not yet)
- Uses git commit -m with the message in quotes (done)
- The message names the change in three words or more (not yet)
- Lists the history with git log --oneline (not yet)
- Reverts HEAD, the commit you just made, with --no-edit (not yet)
Quick check
You shortened the headline in index.html, and you're halfway through new footer styles in footer.css. What do you commit now?
Watch next
Watch it for The words repository, staging and commit, each shown in a few seconds, so the terms in this lesson stick.
Watch it for Where the Source Control view lists changed files, and how staging and committing look when you click instead of type.
Connects to: 1.2 Setting up your computer · 1.3 First steps with Claude Code · 9.4 Versioning and releases · 13.5 Coding agents in a real codebase · 19.4 CI and safe releases
Sources · checked Nov 2026
- Git: download page, latest source releaseGit 2.56.1, released 26 Oct 2026
- Git documentation: git-revertgit revert records new commits that reverse the effect of earlier ones, and reset or restore discard uncommitted work instead
- Git documentation: git-commit, DiscussionBegin the message with one short line of no more than 50 characters; the text up to the first blank line is the title Git uses throughout
- Git documentation: git-initA repository is a .git directory inside the project folder
- Git documentation: gitignoreA .gitignore file lists files Git should leave untracked
- npm Docs: npm install (v11)npm install with no arguments installs the dependencies to the local node_modules folder (the breakIt line)
- VS Code Docs: Staging and committing changesU, M and D letters in the Source Control view, staging with the plus icon, the Commit button, and Undo Last Commit for a commit you haven't pushed
- VS Code: release notes (Updates)VS Code 1.148 is the current release
- Claude Code Docs: Checkpointing/rewind restores edits made by Claude's file editing tools; 'A file that only Bash commands changed isn't tracked and stays as it is. To revert it, use version control, such as Git.'; snapshots are deleted by default about 30 days after the session last saved one; checkpoints are not a replacement for version control
- Claude Code Docs: changelogClaude Code 2.1.332 (25 Nov 2026), from the course fact sheet
- Figma Help: View a file's version historyFigma records a checkpoint every 30 minutes, and restoring a version adds checkpoints instead of deleting later ones