Git and GitHub for Vibe Coders
Branches, pull requests, and review — the workflow that makes AI-generated changes safe to undo.
Read first: What You Need Before You Start
Git has been the safety net under every chapter so far. Now use it properly: branches that make experiments free, and pull requests that give you a place to review AI output before it becomes permanent.
The four commands you will actually use
Git has hundreds of commands. Day to day you need four, plus one for emergencies.
$ git status # what has changed$ git add . # stage everything$ git commit -m "message" # save a snapshot$ git push # send it to GitHubAnd the one that makes the rest safe:
$ git restore . # throw away uncommitted changesBranches make experiments free
A branch is a parallel copy of your project. Work on it, and main stays exactly as it was until you decide otherwise.
$ git switch -c add-dark-mode # create and move to a branch# ... prompt, review, commit ...$ git switch main # back to safety$ git branch -D add-dark-mode # delete the experimentThis changes how you can work with an AI. A large or speculative request stops being risky, because the worst case is deleting a branch. You can let an agent attempt something ambitious knowing that rejecting all of it costs one command.
Read the diff before you stage it
git add . stages everything indiscriminately, including whatever the AI touched that you never asked about. That habit is forgivable for code you wrote yourself and already know. It is a bad one to inherit for a diff you have not read end to end.
git diff shows every change before anything is staged. Read all of it, not just the file you expected — models edit configuration, delete comments, or quietly “fix” something you never mentioned, more often than a human collaborator would.
$ git diff # everything unstaged, file by file$ git add -p # stage hunk by hunk, skip what you don't want$ git diff --staged # confirm exactly what's about to be committedCommit messages are notes to your future self
You will read these when something breaks and you are trying to find where it came from. Write what changed and why — not what files were touched, which git already knows.
- 1Weak
“updates”, “fix”, “wip”, “changes from AI”
- 2Useful
“Fix double-counted discount when two coupons apply”
You can hand this off, and the result is usually better than what people write by hand:
Look at my staged changes and write a commit message.One short summary line, then a blank line, then a couple oflines on why the change was needed.Pull requests: a place to actually review
A pull request proposes merging your branch into main. Even working alone it is worth it, because GitHub shows you the complete diff in a readable view — which is a far better review surface than an editor as changes stream past.
- 1
Push your branch
git push -u origin add-dark-mode
- 2
Open the PR
GitHub prompts you, or use gh pr create.
- 3
Read the whole diff
This is the review. Look for things you did not ask for as much as for bugs.
- 4
Merge, then delete the branch
GitHub offers both in one click.
When it goes wrong
- 1Committed something you should not have
git reset --soft HEAD~1 undoes the commit and keeps the changes staged.
- 2An AI change already merged to main turns out to be wrong
git revert <sha> undoes it with a new commit, instead of rewriting history that others may have already pulled — the right tool once a change is shared.
- 3Committed a secret
Rotate the key. It is in the history now, and removing it from the current files does not remove it from the repo.
- 4Branch is a mess
Switch back to main and delete it. That is what branches are for.
- 5Merge conflict
Paste both versions and the conflict markers to the AI with context on what each side was doing — this is one of the things it is good at.
Key takeaways
- Four commands cover daily work: status, add, commit, push.
- git restore . is the undo that makes accepting AI changes safe — as long as you commit often.
- Read the diff, ideally hunk by hunk with git add -p, before you stage a change you did not write yourself.
- Branches make ambitious requests free, because rejecting everything costs one command.
- Write commit messages about why, not which files. Or have them written from the diff.
- Review the diff on GitHub, not in your editor. You will catch different things.
- Once a change is merged and shared, revert it forward — don't rewrite history other people already pulled.
- A committed secret must be rotated. Deleting the line does not remove it from history.
Quick check
Answer these to unlock the next chapter — 3 of 4 to pass. You can retake it anytime.
Answer every question to check.
Make a free account to read on
Every chapter is free — an account is how your progress, XP, and streak follow you from your laptop to your phone, and how you show up on the leaderboard. No payment, no trial.