Git Basics — 8 commands you'll use every day
You Only Need a Handful
There are hundreds of Git commands. You will use about eight of them for 90% of everything you do in this course. That's it.
Here's the freeing part: Claude Code can run every one of these for you. You can literally type "commit my changes and push them" and it handles the mechanics. So why learn the commands at all? Because when you understand what each one does, you can ask precisely for what you want, spot when something's off, and never feel lost when Claude tells you what it just did.
Let's walk through each command.
Setup (One Time Only)
Before using Git for the very first time, tell it who you are:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
Use the same email you'll use for GitHub. This is how your commits get labeled with your name.
1. git init — Start Tracking a Folder
Turns an ordinary folder into a Git repository.
cd ~/Documents/focus-dashboard
git init
This creates the hidden .git folder inside your project. From this moment on, Git is watching.
If you created your project with create-next-app, it likely ran git init for you already. To check:
git status
If you see output instead of an error, Git is already initialized.
2. git status — See What's Changed
Shows which files have changed, what's staged, and what Git isn't tracking yet.
git status
You'll see something like:
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
app/dashboard/page.tsx
components/TaskList.tsx
nothing added to commit but untracked files present
Run git status often. It's free information about exactly what's going on.
3. git add — Stage Changes
Marks the changes you want to include in your next commit.
# Stage one specific file
git add app/page.tsx
# Stage everything that changed
git add .
The . means "everything in this folder and below." For most commits, git add . is all you need.
After staging, run git status again to confirm what's queued up.
4. git commit — Save a Snapshot
Permanently records the staged changes.
git commit -m "Add task list with checkbox toggle"
The -m flag lets you write the message inline, in quotes.
Writing good commit messages: start with a verb, keep it under about 50 characters.
Add user authenticationFix task deletion bugUpdate homepage layout for mobileConnect Supabase database
When Claude Code commits for you, it writes these messages automatically. If one isn't clear, just ask:
"Commit this with a message that says we added the dark mode toggle."
5. git log — See Your History
Lists every commit, newest first.
git log
Output:
commit a3b4c5d6e7f (HEAD -> main)
Author: David <david@example.com>
Date: Mon Jan 15 10:30:00 2024
Add task deletion with confirmation
commit 1234567890a
Author: David <david@example.com>
Date: Mon Jan 15 09:15:00 2024
Set up project structure and navigation
Press q to exit the log view.
For a cleaner, one-line-per-commit view:
git log --oneline
6. git diff — See Exactly What Changed
Shows the specific lines that changed before you commit.
git diff
Lines starting with + were added. Lines starting with - were removed. This is handy when you've made several changes and want to review before saving.
"Show me what changed since my last commit and explain it in plain English."
Claude Code reads the diff and translates it for you.
7. git checkout — Visit a Previous State
Lets you jump back to an earlier commit to see what your app looked like then.
# Visit a specific commit (use the first 7 characters of its ID)
git checkout a3b4c5d
# Return to the latest version
git checkout main
Important: always come back to main when you're done looking around. Don't make changes while parked on an old commit (Git calls this a "detached HEAD" state) — it can get confusing fast.
8. git restore — Undo Local Changes
Throws away uncommitted changes and resets a file to its last committed state.
# Undo changes to one file
git restore app/page.tsx
# Undo all uncommitted changes (careful — this is permanent)
git restore .
Warning: git restore permanently discards uncommitted work. Reach for it when you've made a mess and want to start fresh from your last commit.
The Daily Rhythm
Here's the loop you'll repeat every time you work on your app:
# 1. Do some work (write code, add features, fix bugs)
# 2. Check what changed
git status
# 3. Stage the changes
git add .
# 4. Commit with a message
git commit -m "Describe what you did"
# 5. Push to GitHub (covered in the next lessons)
git push
Or, in one sentence to Claude Code:
"Stage everything, commit it with a clear message, and push to GitHub."
How Often Should You Commit?
A rough guide:
- After finishing a feature or a meaningful chunk of work
- Right before a big change (so you have a safe restore point)
- At the end of every work session, before you close your laptop
- At minimum, once a day while you're actively building
You can never commit too often. You can absolutely commit too rarely.
Common Mistakes and Fixes
"I forgot to commit before a big change."
Run git diff to see everything you changed. If it's a lot, you can still split it into several commits by staging specific files one at a time with git add [filename].
"My commit message was wrong."
If you haven't pushed yet: git commit --amend -m "Correct message"
"I staged the wrong files."
Unstage them: git restore --staged [filename] or git restore --staged .
"Everything is broken and I want my last commit back."
git restore . reverts all uncommitted changes. Use with care — it can't be undone.
For any of these, you can also just describe the situation to Claude Code and let it run the right command.
Summary
| Command | What It Does |
|---|---|
git init | Start tracking a folder with Git |
git status | See what's changed |
git add . | Stage all changes |
git commit -m "..." | Save a snapshot with a message |
git log --oneline | See commit history |
git diff | See exact changes before committing |
git checkout [id] | Visit an old commit |
git restore . | Undo uncommitted changes |
- These eight commands cover almost everything you'll do
- The daily rhythm is: work →
git status→git add .→git commit→git push - Commit small and often — frequent commits are a safety net
- Claude Code can run all of these for you; knowing them lets you ask precisely and stay in control