Git Workflow
What you'll learn
~20 min- Initialize a new git repository with git init
- Use the stage-then-commit workflow (git add, git commit)
- Write clear, descriptive commit messages
- Apply the commit-before-AI pattern to protect your work
By the end of this lesson, you’ll be able to create a git repository, stage your changes, and commit them — the three-step workflow you’ll repeat every time you work on a project.
The Mental Model: Packing a Shipment
Think of saving your work in git like packing a box to ship:
- Your desk is the working directory — files are spread out, some changed, some new.
- The packing table is the staging area — you pick which items go in this particular box.
- Sealing and labeling the box is the commit — you write what’s inside and it’s saved.
You don’t have to pack everything at once. You choose what goes in each box, label it clearly, and stack the sealed boxes on a shelf where you can always open any of them later.
The Three-Step Workflow
Using git day-to-day requires just three steps:
- Make changes to your files (or let the AI do it)
- Stage the changes you want to save (
git add) - Commit them with a message (
git commit)
That’s it. Let’s walk through each one.
Step 0: Create a Repository
Before git can track a project, you need to initialize it:
mkdir my-projectcd my-projectgit initgit init creates a hidden .git folder inside your project. This is where git stores all the version history. You never need to touch this folder — git manages it automatically.
You only run git init once per project — when you first create it. After that, git can track changes in this folder, but each new file must be added (git add) before it becomes tracked. If you clone a project from GitHub, it is already initialized.
The hidden .git folder is the repository — it contains your entire version history. If you delete it, all your commit history is gone. Leave it alone and let git manage it.
Step 1: Make Changes
Create some files (or let your AI tool create them):
touch index.htmltouch style.cssecho "# My Project" > README.mdAt this point, git knows these files exist but hasn’t saved them yet. They’re “untracked.”
Step 2: Stage Changes (git add)
Staging tells git which changes you want to include in your next commit. Think of it as putting items on the packing table before sealing the box.
git add index.html style.css README.mdOr, to stage everything:
git add .The . means “everything in the current directory” (except files listed in your .gitignore).
git add . stages everything, including files you might not want to commit — like .env files with API keys or bulky node_modules/ folders. In the exercises here, that’s fine because there are no secrets to leak. In real projects, always set up a .gitignore file first — you’ll learn how in Lesson 4. Until then, prefer staging specific files by name: git add index.html style.css.
Sometimes you’ve made changes to 10 files, but you only want to save 3 of them right now. Staging lets you pick and choose. You can also stage specific files: git add index.html style.css instead of everything. For most learning purposes, git add . (stage everything) works fine as long as your .gitignore is set up.
Step 3: Commit (git commit)
A commit is the actual save point. Every commit has a message describing what changed:
If this is your very first commit ever, git will ask you to identify yourself. Run these two commands once (you did this in Lesson 1, but if you skipped it):
git config --global user.name "Your Name"git config --global user.email "you@example.com"The --global flag means this applies to all git projects on your machine.
git commit -m "Add initial project files"The -m flag lets you write the message inline. The message should be short and describe what you did.
Good commit messages:
"Add login page with form validation""Fix broken link in navigation""Update styles for mobile responsiveness"
Bad commit messages:
"stuff"— too vague"asdfgh"— meaningless"I made some changes"— no useful information
🔍Commit message conventions
Professional developers often follow a pattern: start with a verb in imperative mood (“Add,” “Fix,” “Update,” “Remove”). Think of completing the sentence “This commit will…” So “Add contact form” rather than “Added contact form” or “Adding contact form.” This isn’t a strict rule for learning, but it’s a good habit to build.
The Complete Flow
Here’s the pattern you’ll repeat hundreds of times:
# 1. Make changes (or let AI make them)# ... edit files, run AI tools, etc.
# 2. Check what changedgit status
# 3. Stage the changesgit add .
# 4. Commit with a descriptive messagegit commit -m "Add contact form with validation"
# 5. (Optional) Verify your commit was savedgit log --onelineThe git status command (step 2) shows you what’s changed since your last commit. It’s your “what happened?” command — use it frequently. You can also run git status at any time between steps to check where things stand. The git log --oneline at the end shows your commit history in a compact list, confirming your work was saved.
Worked Example: The Commit-Before-AI Pattern
This is the most important git habit you’ll build. Every time you’re about to ask an AI tool to make changes, commit first. Here’s a complete walkthrough:
# You've been working on a project — commit what you havegit add .git commit -m "Working homepage with header and hero section"
# Now ask Claude Code to add a new featureclaude> "Add a contact form to the homepage with name, email, and message fields"
# Claude edits index.html, creates contact.js, modifies style.css# Check what changedgit status# modified: index.html# modified: style.css# new file: contact.js
# It looks good — save this progressgit add .git commit -m "Add contact form with client-side validation"Now suppose you ask Claude for another change and it breaks things:
# Ask Claude for something ambitious> "Redesign the entire page layout to use a sidebar navigation"
# Check the result... the page is broken# No problem — revert to the last working commitgit restore .That one command — git restore . — throws away all uncommitted changes in tracked files and restores them to the last commit. Your contact form is back, working perfectly. This is why you always commit before asking the AI to make big changes.
If the AI created brand-new files, git restore . will not remove them — they remain as “untracked” files. You will need to delete them manually or use git clean -fd (which permanently removes untracked files and folders). Always check git status after restoring.
🧬In Your Field: Biotechclick to expand
This pattern is especially valuable when you’re using AI to generate or modify analysis scripts. Commit your working pipeline before asking Claude to “optimize the statistical analysis” or “add a new visualization.” If the optimization introduces a bug in your data processing, you can revert instantly instead of debugging someone else’s refactoring of your code.
🏛️In Your Field: Government / State Devclick to expand
In professional and government environments, traceability matters. Each commit creates a documented record: “At 2:30 PM, the configuration was working. At 2:45 PM, we asked the AI to modify the data processing script. At 2:50 PM, we reverted because the output changed.” This kind of timeline is invaluable when explaining changes to supervisors or during compliance reviews.
The Staging Area Visual
Think of it like preparing a package to ship:
Working Directory → Staging Area → Repository(your files) (git add) (git commit)
index.html ─────────→ index.html ──────→ Commit #1 style.css ─────────→ style.css ──────→ "Add initial files" app.js (not added)Files in the working directory that aren’t staged won’t be included in the commit. This gives you control over exactly what gets saved.
📊In Your Field: MIS / Businessclick to expand
Think of each commit as a checkpoint in a project management workflow. If you’re building a dashboard with AI assistance and the stakeholder says “actually, go back to what we had Tuesday,” you can find Tuesday’s commit and restore it. In business settings, this kind of rollback capability saves hours of rework and keeps client deliverables on track.
When Things Go Wrong
Use the Symptom → Evidence → Request pattern: describe what you see, paste the error, then ask for a fix.
Key Takeaways
- Three commands are all you need:
git add .to stage,git commit -m "message"to save,git statusto check. - Always commit before asking the AI to make changes. This is your most important safety habit.
- git init starts tracking a folder. You only need to do this once per project.
- Staging gives you control. You choose exactly which changes go into each commit.
- If AI changes break something, revert.
git restore .throws away all uncommitted changes to tracked files and takes you back to your last save point.
You're about to ask Claude Code to refactor your entire project. What should you do first?