Building Module 7 · Git: Your Safety Net

Saving Your Work

Last reviewed

Beginner

What you'll learn

~20 min
  • Use git status, git log, and git diff to understand your project state
  • Undo mistakes with git restore and git reset
  • Push your local repository to GitHub for backup and collaboration
  • Follow the daily orchestrator workflow: status, work, add, commit, push

By the end of this lesson, you’ll know how to inspect your project’s history, undo mistakes, and back up your work to GitHub — completing the full version control toolkit you need as an AI orchestrator.

The Mental Model: Your Project’s Dashboard and Time Machine

In the last lesson, you learned to save snapshots with commits. Now you need two more abilities:

  • A dashboard — so you can see what’s happening in your project right now (what changed? what’s saved? what’s pending?)
  • A time machine — so you can look at past snapshots and, when needed, go back to one

Git gives you both. Three commands make up your dashboard (status, log, diff), and a couple more give you the time machine (restore, reset).

Your Dashboard: Three Inspection Commands

git status — What’s Changed Right Now?

Terminal window
git status

This shows:

  • Untracked files — new files git doesn’t know about yet
  • Modified files — existing files that have changed
  • Staged files — files ready to be committed

Run this frequently. It’s your most-used command — the first thing you type when you sit down to work, and the command you check after every AI interaction.

git log — What Have I Committed?

Terminal window
git log --oneline

This shows a list of your commits, newest first:

a1b2c3d Add contact form with validation
e4f5g6h Update homepage hero section
i7j8k9l Initial commit

Each line shows a unique commit ID (the letters/numbers) and your commit message. The --oneline flag keeps it compact.

ℹStuck in a scrolling screen?

If the output is long, git will open a viewer (called a pager). Use your arrow keys to scroll, and press q to quit and return to your terminal. This catches many beginners off guard — just remember: q to quit.

💡Why commit messages matter — right here

Look at that log. Can you tell what the project looks like at each point? Good commit messages make your log a readable story of your project. Bad messages (“stuff,” “update,” “fix”) make the log useless. When you need to revert, a clear log is the difference between finding the right commit in seconds versus guessing.

git diff — What Exactly Changed?

Terminal window
git diff

This shows line-by-line what has changed in your unstaged files. Lines starting with + were added, lines starting with - were removed. If you have already staged changes with git add, use git diff --staged to see those instead.

<h1>Welcome</h1>
<h1>Welcome to My Portfolio</h1>

This is especially useful after an AI tool makes changes. Before you commit, run git diff to review exactly what the AI modified. Think of it as proofreading before you sign off.

Read your history

In your own terminal, inside your ai-class folder, run:

Terminal window
git log --oneline

Each line is one checkpoint: a short ID and the message. If you have only one or two, ask your agent to save a checkpoint after each small change and look again.

Worked Example: Reviewing AI Changes Before Committing

Here’s a reference session walkthrough after you ask Claude Code to update your project and want to review what it did before saving (in daily work, you can run these commands yourself or ask your agent to show the diff and save a checkpoint for you):

Terminal window
# You already have a clean commit
# Claude Code modified several files
# Step 1: See which files were touched
git status
# Changes not staged for commit:
# modified: index.html
# modified: style.css
# Untracked files:
# utils.js
# Step 2: See the actual changes
git diff
# Shows line-by-line changes in index.html and style.css
# (New files won't appear in git diff. Stage them first with
# git add, then use git diff --staged to see their contents.)
# Step 3: Everything looks good — stage and commit
git add .
git commit -m "Add utility functions and update page layout"
# Step 4: Verify the commit is saved
git log --oneline
# f8a9b1c Add utility functions and update page layout
# a1b2c3d Previous commit message...

This review habit — status, then diff, then add and commit — takes 30 seconds and prevents you from accidentally saving broken changes.

🧬In Your Field: Biotechclick to expand

When an AI tool modifies a data analysis script, git diff becomes your peer reviewer. You can see exactly which lines of your analysis changed before you commit. Did the AI accidentally remove a normalization step? Did it change a p-value threshold? Reviewing the diff catches these issues before they become buried in your project history.

Your Time Machine: Undoing Mistakes

One of git’s greatest powers is letting you undo things. Here are the commands you’ll actually need:

Undo Changes to a Specific File (Before Committing)

Terminal window
git restore filename.txt

This throws away the file’s unstaged changes, putting it back to its last committed version (or to the version you staged with git add, if you staged it). Those changes are gone.

Undo All Unstaged Changes

Terminal window
git restore .

This discards unstaged changes in all tracked files. Use with caution: those changes are lost. Anything you already staged with git add survives; to discard staged changes too, run git restore --staged --worktree .. Untracked files (brand-new files the AI created) remain; remove them manually or with git clean -fd.

Undo the Last Commit (Keep the Changes)

Terminal window
git reset --soft HEAD~1

(HEAD means “where we are right now,” and ~1 means “go back one step.” So HEAD~1 = the commit before the current one.)

This undoes the commit but keeps your file changes. Useful when you committed too early or with the wrong message.

⚠When in doubt, commit first

Before running any AI tool or making big changes, ask your agent to save a quick Git checkpoint. This guarantees you can always get back to a working state.

Undo an edit safely

Ask your agent to save a checkpoint first. Then ask it to make a small change you do not want, and finally ask:

Throw away that last change and put the files back to the last checkpoint.

Check with git status in your own terminal. It should report a clean working tree.

🔍git restore vs. git checkoutclick to expand

Git 2.23+ introduced git restore as a clearer alternative to the older git checkout for undoing changes. We use git restore in this course because it does exactly one thing and is less confusing. If you see git checkout . or git checkout -- filename in older tutorials or AI-generated suggestions, they do the same thing as git restore. Both work fine.

Pushing to GitHub

So far everything is saved only on your computer. Backing it up to GitHub needs an account first, so that is the next lesson. In Lesson 4 you will ask your agent to publish the project for you.

The Daily Workflow

Here’s a reference walkthrough of the complete cycle you’ll follow for every project (in daily work, you can either run these commands in your terminal or ask your agent to run checkpoints and pushes for you):

Terminal window
# Start of work session
git status # Check current state
# Save point before AI work
git add .
git commit -m "Save point: working homepage"
# Make changes (AI tools, manual editing, etc.)
claude # or agy, codex, copilot
> "Add a navigation bar to the site"
# Review what changed
git status # See which files were touched
git diff # See line-by-line changes
# Save your work
git add .
git commit -m "Add responsive navigation bar"
# Back up to GitHub
git push

Repeat this cycle as many times as you like during a session. Each commit is a save point. Each push is a backup.

Quick Reference

I want to…Command
See what’s changedgit status
See commit historygit log --oneline
See exact line changesgit diff
Stage all changesgit add .
Commit changesgit commit -m "message"
Push to GitHubgit push
Undo unstaged changesgit restore .
Undo last commit (keep files)git reset --soft HEAD~1
🔧

When Things Go Wrong

Use the Symptom → Evidence → Request pattern: describe what you see, paste the error, then ask for a fix.

Symptom
git push fails with 'rejected' error
Evidence
! [rejected] main -> main (fetch first) / Updates were rejected because the remote contains work that you do not have locally
What to ask the AI
"My git push was rejected because the remote has changes I don't have locally. How do I pull the remote changes and then push mine?"
Symptom
git push asks for username/password and fails
Evidence
remote: Support for password authentication was removed. Please use a personal access token instead.
What to ask the AI
"GitHub isn't accepting my password for git push. How do I set up a personal access token or SSH key for authentication?"
Symptom
git diff shows nothing even though I made changes
Evidence
Running git diff produces no output, but git status shows modified files
What to ask the AI
"git diff shows nothing but I know I changed files. Could my changes already be staged? How do I see the diff of staged changes?"
Symptom
I ran git restore . and lost changes I wanted to keep
Evidence
All my uncommitted work is gone after git restore .
What to ask the AI
"I accidentally reverted all my changes with git restore and lost work. Is there any way to recover uncommitted changes, or are they gone?"

Key Takeaways

  • git status is your most-used command. Run it before and after everything — it shows you what git sees.
  • Review before committing. Use git diff to check what an AI tool actually changed before you save it.
  • A commit is your way back. git restore . throws away unstaged changes in tracked files (anything you staged survives; git restore --staged --worktree . discards both). git reset --soft HEAD~1 undoes a commit but keeps your files.
  • Push to GitHub for backup. After the one-time setup, git push backs up your work in seconds.
  • The daily cycle is simple: status, commit, work with AI, review, commit, push. A small set of commands you will repeat: status, diff, add, commit, push.

You now know enough git for most of what you’ll do day to day as an orchestrator. There’s much more to git (branches, merging, rebasing), but you can learn those when you need them, and even then you can ask your AI tool to help you with the commands.

KNOWLEDGE CHECK

You ran git diff and it shows no output, but git status shows modified files. What's most likely happening?

KNOWLEDGE CHECK

What's the correct order for the daily AI orchestrator workflow?

Search lessons