Building Module 7 · Git: Your Safety Net

Saving Your Work

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 (checkout, 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.

TRY ITView a compact list of all your previous commits
$

Worked Example: Reviewing AI Changes Before Committing

Here’s a realistic scenario. You asked Claude Code to update your project, and now you want to review what it did before saving:

Terminal window
# You already have a clean commit
# Claude Code modified several files
# Step 1: See which files were touched
git status
# modified: index.html
# modified: style.css
# new file: 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 reverts the file to its last committed version. The changes are gone.

Undo All Changes Since Last Commit

Terminal window
git restore .

This discards unstaged changes in all tracked files. Use with caution — all uncommitted changes to tracked files are lost. 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, do a quick git add . && git commit -m "Save point before changes". This guarantees you can always get back to a working state.

TRY ITUndo all uncommitted changes and restore files to the last commit
$
🔍git restore vs. git checkout

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 has been local — saved on your computer only. To back up your work and share it, push to GitHub.

💡Easier method in the next lesson

The steps below walk through the manual setup. Lesson 4 covers a one-command alternative using the GitHub CLI (gh repo create --push) that handles all of this automatically. If you prefer the faster path, skip ahead to Lesson 4 and come back here only if you need the manual method.

Step 1: Create a GitHub Repository

  1. Go to github.com and sign in (create an account if needed)
  2. Click the + button, then New repository
  3. Name it (e.g., my-project)
  4. Keep it Public or Private — your choice
  5. Don’t add a README, .gitignore, or license (you already have files)
  6. Click Create repository

Step 2: Connect Your Local Project to GitHub

GitHub will show you commands. Copy and run them:

Terminal window
git remote add origin https://github.com/YOUR-USERNAME/my-project.git
git branch -M main
git push -u origin main

Let’s break these down:

  • git remote add origin — tells git where to upload (the GitHub URL)
  • git branch -M main — renames your branch to “main” (the convention)
  • git push -u origin main — uploads your commits to GitHub

Step 3: Future Pushes

After the initial setup, pushing new work is just:

Terminal window
git push

One command. Your code is backed up in the cloud.

If push fails

Two common issues:

Authentication error: GitHub no longer accepts passwords. Run gh auth login (from the GitHub CLI) to authenticate via your browser, or set up a Personal Access Token at github.com/settings/tokens.

Rejected push (remote has new changes): Run git pull --rebase origin main to incorporate the remote changes, then git push again.

📊In Your Field: MIS / Businessclick to expand

Think of GitHub as your project’s cloud backup with collaboration built in. In business contexts, having your work on GitHub means a colleague can pick up where you left off, your supervisor can review progress, and nothing is lost if your laptop dies. For team projects — dashboards, automation scripts, report templates — GitHub becomes the single source of truth that everyone works from.

🏛️In Your Field: Government / State Devclick to expand

Some government environments restrict access to public GitHub. Your agency may use GitHub Enterprise, GitLab, or Azure DevOps instead. The git commands are identical — the only difference is the URL in git remote add origin. Check with your IT team about which hosting service is approved. The key point remains: get your work off your local machine and into a backed-up, shared repository.

The Daily Workflow

Here’s the complete workflow you’ll follow for every project:

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 gemini, codex, etc.
> "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 uncommitted 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.
  • Undo is always available. git restore . reverts tracked files to the last commit. 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 95% of what you’ll do 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?