🧬 Module 01 — Git Fundamentals
This is the module. The one you’ll actually use every single working day for the rest of your career. Everything after this is a specialization — this is the core.
By the end of this module you will be able to:
✓ Explain why Git has a staging area at all, not just “what it does”
✓ Stage exactly the changes you want, even out of a messy working directory
✓ Write commit messages your future self will actually thank you for
✓ Create, switch, and merge branches — the loop you’ll run dozens of times a day
✓ Use git stash to context-switch without committing half-finished work
[!TIP] Still have
~/git-playgroundfrom Module 00? Use it. Every Try It block below assumes a real terminal, not just reading along.
📑 In This Module
- New Files — Tracked vs. Untracked
- Staging — The Most Important Concept in Git
- Commit
- History
- Tagging
- Stash
- Branch
- Merge
- Workflow — Putting It All Together
- Best Practices
- Glossary (Module 01 Terms)
📄 New Files — Tracked vs. Untracked
When you create a new file inside a Git repo, Git notices it immediately — but doesn’t track it
until you say so. This is deliberate: Git doesn’t want to auto-track your node_modules folder,
your .DS_Store files, or your secret notes_to_self_do_not_commit.txt.
echo "console.log('hello world')" > app.js
git status
Untracked files:
(use "git add <file>..." to include in what will be committed)
app.js
Untracked = “Git sees this file exists, but has zero interest in it until you tell it otherwise.” This is a feature, not Git being lazy.
⌨️ TRY IT YOURSELF (in ~/git-playground)
echo "console.log('hello world')" > app.js
git status
What should I see? app.js listed under “Untracked files,” with Git explicitly suggesting
git add — not an error, just Git telling you exactly what to do next.
📦 Staging — The Most Important Concept in Git
🎭 The real-life example
You’re packing a box to ship. Your desk (the working directory) has 20 items scattered around. You don’t ship your whole desk — you deliberately pick which items go into the box (the staging area), inspect what’s in the box one more time, and then seal and ship it (the commit).
The staging area exists so you can build exactly the commit you want, even if your working directory is a mess of five unrelated changes at once.
graph LR
A[Working Directory<br/>📝 your messy desk] -->|git add| B[Staging Area<br/>📦 the box you're packing]
B -->|git commit| C[Repository / .git history<br/>🚚 shipped & permanent]
style A fill:#fff3cd,color:#1a1a1a
style B fill:#cfe2ff,color:#1a1a1a
style C fill:#d4edda,color:#1a1a1a
💻 The technical example
# You edited THREE files, but they're unrelated changes
echo "fix bug" >> login.js
echo "new feature" >> signup.js
echo "typo fix" >> readme.md
git status
# modified: login.js
# modified: signup.js
# modified: readme.md
# Stage ONLY the bug fix — not the other two, even though they're all "modified"
git add login.js
# Check the box before sealing it
git status
# Changes to be committed:
# modified: login.js
# Changes not staged for commit:
# modified: signup.js
# modified: readme.md
git commit -m "fix: login validation bug"
# ^ Only login.js goes in. signup.js and readme.md are still sitting on your desk, untouched.
Common staging commands:
git add file.txt # stage one specific file
git add file1.txt file2.txt # stage multiple specific files
git add . # stage EVERYTHING changed (use carefully — see Best Practices below)
git add -p # stage interactively, chunk by chunk within a single file (genuinely great)
git reset file.txt # UN-stage a file (doesn't touch its actual content — just takes it back out of the box)
[!TIP]
git add -pis the most underrated command for beginners. It walks through every changed chunk in a file and asks “stage this part? y/n” — perfect for when you fixed a bug AND accidentally left aconsole.log('here')debug line in the same file, and want to commit only the fix.
⌨️ TRY IT YOURSELF (in ~/git-playground)
echo "fix bug" >> login.js
echo "new feature" >> signup.js
git add login.js
git status
What should I see? login.js under “Changes to be committed,” signup.js still sitting
under “Changes not staged for commit” — proof the staging area really does let you pick exactly
what goes in, even when more than one file changed.
🎯 YOUR TURN
You have two modified files: login.js and signup.js. Stage only signup.js, confirm it
with git status, then unstage it again without touching its actual content. Can you do it
without looking at the solution first?
💡 Show solution
```bash git add signup.js git status # signup.js now under "Changes to be committed" git reset signup.js git status # signup.js back under "Changes not staged" — content untouched ``` `git reset⌨️ TRY IT YOURSELF (in ~/git-playground)
git commit -m "fix: login validation bug"
git log --oneline -1
What should I see? A one-line confirmation from git commit (branch, short hash, file stats),
then that same commit as a single line from git log.
🚨 COMMON MISTAKE
Committing “today’s work” as one giant commit at the end of the day. It feels efficient in the
moment and is genuinely painful later — git revert (Module 04) undoes one commit, so a
50-file mega-commit means reverting the one real bug inside it also reverts 49 unrelated changes
you didn’t want touched. Small, focused commits aren’t a style preference; they’re what makes
every later Git operation (revert, cherry-pick, bisect) actually usable.
⌨️ TRY IT YOURSELF (in ~/git-playground)
git log --oneline
git log --graph --oneline --all
What should I see? The same commits, but the second command draws them as a small ASCII tree. On one branch with no merges yet it’ll look like a straight line — that’s expected. It gets genuinely useful once branches exist, a few sections from now.
⌨️ TRY IT YOURSELF (in ~/git-playground)
git tag -a v0.1.0 -m "First playground milestone"
git tag
git show v0.1.0
What should I see? v0.1.0 listed by git tag, and git show printing the tag’s own
message plus the full commit it points at.
⌨️ TRY IT YOURSELF (in ~/git-playground)
echo "half-done work" >> login.js
git status # shows login.js modified
git stash
git status # clean — login.js looks untouched
git stash pop
git status # the change is back
What should I see? git status reporting a clean working directory right after stash, then
the exact same modification reappearing after pop — nothing was lost, it was just parked.
🧪 SDET SCENARIO
You’re mid-way through writing a new Playwright test, it’s not passing yet, and a flaky test in
CI just paged you to investigate right now. You can’t commit broken, half-finished test code —
but you also can’t lose 40 minutes of locator work. git stash, switch branches, debug the
flaky test, fix it, switch back, git stash pop, and you’re exactly where you left off. This is
the single most common real reason test engineers reach for stash.
⌨️ TRY IT YOURSELF (in ~/git-playground)
git switch -c feature/login
git branch
What should I see? feature/login listed with a * next to it, confirming you’re now on
the new branch — main is still exactly where you left it.
🎯 YOUR TURN
You’re currently on feature/login. Create a second branch called feature/payment, make one
commit on it (any trivial change), then switch back to main. Do NOT look at the solution first.
💡 Show solution
```bash git switch -c feature/payment echo "payment stub" >> payment.js git add payment.js git commit -m "feat: stub out payment module" git switch main ``` Run `git log --oneline --graph --all` afterward — you'll see `main`, `feature/login`, and `feature/payment` as three separate pointers, with `feature/payment` one commit ahead of where it branched off.since branch was created] --> A3[main just 'catches up'
— no new merge commit] end subgraph "Three-Way Merge" B1[main moved forward too] --> B2[Git combines BOTH histories] --> B3[Creates a new
merge commit] end style A3 fill:#d4edda,color:#1a1a1a style B3 fill:#cfe2ff,color:#1a1a1a ``` - **Fast-forward**: nobody touched `main` while you were on your branch — Git just moves `main`'s pointer forward to your latest commit. Clean, simple, no extra commit created. - **Three-way merge**: `main` moved forward too (someone else merged something) — Git has to combine both histories, creating a dedicated **merge commit** that has two parents. ### 🎭 The real-life example Two people edited the same shared document while offline, then reconnect. If one person made zero changes, the other's version just "wins" cleanly (fast-forward). If **both** made changes, someone (Git, automatically, usually successfully) has to intelligently combine both sets of edits into one final document (three-way merge) — and if both edited the *exact same sentence* differently, that's a **merge conflict**, which needs a human to decide. (Full conflict-resolution workflow is in [Module 05](../05-advanced-git/).)
⌨️ TRY IT YOURSELF (in ~/git-playground)
git switch main
git merge feature/login
git log --oneline --graph --all
What should I see? Since main hasn’t moved since you branched, this is a fast-forward —
no merge commit, main’s pointer just catches up to feature/login’s latest commit.
🧠 Quick Check: If you'd made a NEW commit directly on main before merging feature/login in, would this still be a fast-forward?
No — the moment `main` has a commit `feature/login` doesn't know about, Git can't just "catch up"
a pointer anymore. It has to combine two divergent histories, which means a three-way merge and a
dedicated merge commit, even if there's no actual conflict between the changes.
a branch] --> B[Edit files] B --> C[git add
stage changes] C --> D[git commit
save a snapshot] D --> E{More changes
needed?} E -->|Yes| B E -->|No, ready| F[git checkout main] F --> G[git merge
your branch] style D fill:#cfe2ff,color:#1a1a1a style G fill:#d4edda,color:#1a1a1a ``` ```bash git checkout -b feature/add-dark-mode # ... edit files ... git add . git commit -m "feat: add dark mode toggle to settings" # ... edit more files ... git add styles.css git commit -m "fix: dark mode contrast on buttons" git checkout main git merge feature/add-dark-mode git branch -d feature/add-dark-mode ``` That's genuinely most of Git, in one loop. Everything else in this course is either a variation on this loop (Module 02's GitHub push/pull), a safety net for when it goes wrong (Module 04), or a specialization for specific situations (Module 05).
🎯 YOUR TURN — Run the whole loop yourself
In ~/git-playground, from main:
- Create a branch called
feature/dark-mode - Make two separate, small commits on it (anything — even two one-line
echochanges to different files) - Switch back to
mainand merge it in - Delete the now-merged branch
Do all four steps without looking at the solution first — this is the exact loop you’ll run for the rest of your career, so it’s worth getting your fingers to do it without thinking.
💡 Show solution
```bash git switch -c feature/dark-mode echo "dark mode css" >> styles.css git add styles.css git commit -m "feat: add dark mode styles" echo "dark mode toggle" >> settings.js git add settings.js git commit -m "feat: add dark mode toggle" git switch main git merge feature/dark-mode git branch -d feature/dark-mode ```🧠 You can now:
✓ Explain why the staging area exists, not just recite what it does
✓ Stage exactly the changes you want, chunk by chunk if needed
✓ Write commit messages that’ll still make sense to you in six months
✓ Create, switch, merge, and delete branches — the daily loop
✓ Shelve half-finished work with git stash without committing it