Git can feel like a black box, commands go in, something happens, but what exactly? The status and diffWhat is diff?A comparison showing exactly which lines were added, removed, or changed between two versions of code. commands pull back the curtain and show you exactly what Git sees. Master these, and you'll never be surprised by what gets committed.
Your most important command: git status
If you remember only one Git command, make it this one. git status tells you everything happening in your repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory. right now:
git statusDecoding the output
Here's what you'll typically see:
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
new file: utils.js
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
modified: style.css
modified: app.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
config.json
notes.txtGit organizes this into three sections:
- Changes to be committed (green): These are staged and ready to commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed.
- Changes not staged (red): Modified files that won't be in the next commit
- Untracked files (red): New files Git doesn't know about yet
Reading diffs like a pro
While git status tells you which files changed, git diff shows you how they changed. This is where you catch mistakes before they become permanent.
git diff before committing. AI tools sometimes insert subtle changes, extra imports, modified configurations, or debug statements, that you didn't ask for. The diff is your safety net to catch unwanted changes before they're permanent.Seeing unstaged changes
Run this to see what would be staged if you ran git add:
git diffThe output looks intimidating at first, but it's logical once you understand it:
diff --git a/app.js b/app.js
index 3f4a2b1..c7d8e9f 100644
--- a/app.js
+++ b/app.js
@@ -15,7 +15,8 @@ function calculateTotal(items) {
let total = 0;
for (const item of items) {
- total += item.price;
+ const tax = item.price * 0.08;
+ total += item.price + tax;
}
return total;
}Let's break this down:
diff --git a/app.js b/app.js, we're comparing versions of app.js--- a/app.js, the old version (what's currently committed or staged)+++ b/app.js, the new version (what's in your working directory)@@ -15,7 +15,8 @@, this chunk starts at line 15, shows 7 lines from the old version and 8 from the new- Lines starting with
-were removed (old code) - Lines starting with
+were added (new code) - Lines with no prefix stayed the same (context)
| Symbol | Meaning | Color |
|---|---|---|
- | Line was removed | Red |
+ | Line was added | Green |
| (no prefix) | Unchanged context | White/Gray |
Checking staged changes
Once you've staged changes with git add, git diff alone won't show them anymore. To see what's staged:
git diff --staged
# Or the older synonym:
git diff --cachedThis compares your staging areaWhat is staging area?A holding zone in Git where you place changes you want to include in your next commit, letting you select exactly which modifications to save. against the last commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed., in other words, it shows exactly what will be in your next commit.
Checking specific files
Sometimes you only care about one file:
# See unstaged changes in a specific file
git diff src/components/Button.tsx
# See staged changes in a specific file
git diff --staged src/components/Button.tsxThe shortcut: short status
When you just need a quick overview, use the short format:
git status -sM README.md ← Modified but not staged
M index.html ← Modified and staged
A new-feature.js ← Added (new file staged)
D old-file.txt ← Deleted and staged
?? untracked.js ← Untracked (Git doesn't know about it)The two-letter codes tell the story:
| Left column | Right column | Meaning |
|---|---|---|
| (empty) | M | Modified in working directory |
| M | (empty) | Modified and staged |
| A | (empty) | Added (new file staged) |
| D | (empty) | Deleted and staged |
| ?? | ?? | Untracked file |
git status -sb. The -b flag adds the current branch and upstream tracking info in a compact format. Many developers alias this to gs for lightning-fast status checks.When to check what
Here's your decision tree:
Before staging:
git status # See what's changed
git diff # Review the actual changesAfter staging, before committing:
git status # Verify what's staged
git diff --staged # Review exactly what will be committedChecking your work:
git status -s # Quick "what's going on" check
git log --oneline -5 # See recent commits for contextYour daily workflow
These commands form the backbone of your Git routine:
# 1. Start by checking what's happening
git status
# 2. Review your changes before staging
git diff
# 3. Stage the changes you want
git add src/components/
# 4. Review what's staged before committing
git diff --staged
# 5. Commit if everything looks good
git commit -m "Add user profile component"
# 6. Verify the clean state
git statusGetting into the habit of checking before you commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. will save you countless headaches. That thirty seconds reviewing your diffWhat is diff?A comparison showing exactly which lines were added, removed, or changed between two versions of code. is how you catch the debugging console.log you forgot to remove, or the typo in your commit message. Your teammates will appreciate your clean commits, and your future self will too.
Quick reference
| Command | What it does | When to use it |
|---|---|---|
git status | Overview of repo state | Before and after every operation |
git status -s | Compact one-line status | Quick check |
git status -sb | Compact with branch info | Quick check with context |
git diff | Show unstaged changes | Before staging |
git diff --staged | Show staged changes | Before committing |
git diff file | Show changes in one file | Focused review |
# Check current status
git status
# See unstaged changes
git diff
# See staged changes
git diff --staged
# Short status format
git status -s