Lesson 8.1: Branches, Meaningful Commits, Pull Requests, and Small Changes
Lesson Quick-Jump (10 Sections)
1. What Are We Learning?
In this lesson, you will learn how to:
- Use Git branches so your working
mainversion always stays safe. - Make small, frequent commits with clear, meaningful messages.
- Open and review Pull Requests (PRs)—even when working solo!
- Keep changes small and understandable for humans and AI agents alike.
2. Why Does It Matter?
info
When you work directly on main and make one giant commit called "updates", two painful things happen:
- If an AI edit goes sideways after 10 changes, untangling what broke is miserable.
- When you work with teammates (or revisit your own code 3 months later), nobody—including you—can tell why a change was made.
Using branches, small commits, and Pull Requests gives you a built-in safety net and a clean, reviewable history—whether you build alone or on a team.
3. Simple Explanation for a Complete Beginner
Imagine writing an important essay:
mainbranch is your clean, published master copy. You never scribble rough experimental edits directly onto it.- A feature branch (e.g.,
feat/add-tag-filter) is your safe draft copy. You build and test there; if an experiment goes badly,mainis completely untouched. - A commit is a labeled bookmark in your draft ("feat: add tag filter API endpoint" instead of "stuff"). Small commits explain what changed and why.
- A Pull Request (PR) on GitHub is a formal review screen comparing your feature branch against
main. Even when working alone, opening a PR lets you read your entire diff cleanly in GitHub's web interface before clicking Merge.
4. Practical Example
Messy Git history (Avoid):
commit a1b2c3: "wip"
commit d4e5f6: "fix stuff"
commit g7h8i9: "everything works now maybe" (42 files changed!)
Clean Git workflow (Follow this):
- Start from an up-to-date
main:git checkout maingit pullgit checkout -b feat/delete-habit - Implement Task 3.2 (Delete Habit) cleanly:
- Commit 1:
feat(api): add DELETE /api/habits/:id endpoint with ownership check - Commit 2:
feat(ui): add delete button and confirmation state to habit item - Commit 3:
test: add integration tests for deleting habits
- Commit 1:
- Push the branch and open a Pull Request on GitHub:
git push -u origin feat/delete-habit
- Read the "Files changed" tab on GitHub line-by-line, confirm tests pass, then merge into
main!
5. Step-by-Step Instructions
- Before starting any new feature or bugfix, create a descriptive branch (
feat/...for features,fix/...for bug fixes,docs/...for documentation). - Keep every branch scoped to ONE task from your development plan—do not mix unrelated bug fixes and UI redesigns into the same branch.
- Inspect
git statusandgit diffbefore every commit to confirm no stray files, debug prints, or secrets are included. - Write a clear commit message answering "What does this change do if applied?" (for example,
fix: trim blank spaces before saving habit title). - Push your branch to GitHub and open a Pull Request.
- Review your own PR diff on GitHub (check every file changed!), verify tests pass, merge it into
main, and pull the updatedmainlocally.
6. Ready-to-Use AI Prompt
Context:
I just finished implementing a scoped task on my feature branch and want to prepare clean Git commits and a Pull Request description.
Here is the output of `git status` and `git diff --stat` (or the summary of changes):
[Paste `git status` and `git diff --stat`, or let the agent inspect `git diff`]
Objective:
Review my uncommitted changes for scope/cleanliness, suggest how to group them into clean commits (if needed), and draft a concise Pull Request description.
Boundaries:
- Do NOT run destructive Git commands (`reset --hard`, `push --force`, `branch -D`).
- Flag any unrelated edits, leftover debug logs, or potential secrets in the diff BEFORE suggesting a commit.
Expected Output:
1. Any cleanup warnings spotted in the diff.
2. Clear, meaningful commit message(s) explaining what changed and why.
3. A short PR summary covering: What changed, Why, and How it was tested.
7. What to Expect from the AI Agent
| Good Response | Warning Sign |
|---|---|
The agent spots a stray console.log("test") or an unintended edit in an unrelated file, suggests 1–2 crisp commit messages, and writes a clear PR checklist. | The agent tries to run git add -A && git push --force without checking git status first. Mandatory rule: Never force-push shared branches or commit blindly without reviewing git status. |
8. What You Must Personally Verify
- Check
git statusandgit diffyourself before committing—verify every changed file belongs to this single task. - Verify tests pass on the branch right before opening or merging the Pull Request.
- Read the PR "Files changed" view on GitHub—reviewing in GitHub's clean side-by-side view often reveals mistakes you missed in your editor.
9. Common Mistakes
- Making giant 30-file branches: Large PRs are exhausting to review, so people skim them and miss bugs. Keep PRs small—one feature or fix per branch.
- Meaningless commit messages:
"fix","update", or"asdf"help nobody when searching history later. - Never pulling
mainafter merging a PR: After merging on GitHub, remember to rungit checkout main && git pulllocally before starting your next branch so you don't build on old code.
10. Small Practical Exercise
- Create a new branch in your project:
git checkout -b docs/update-test-notes(or a small feature/fix branch). - Make one small, focused improvement, inspect
git diff, commit with a clear message, and push the branch to GitHub. - Open a Pull Request on GitHub, review the Files changed tab carefully, verify checks pass, and merge it into
main.
Completed the exercise? Track your progress
Check off this lesson in PROGRESS-CHECKLIST.md once you have verified every step in Section 8.