Part 6 of 7 · Chapter 1 of 3

Git and GitHub for Vibe Coders

Branches, pull requests, and review — the workflow that makes AI-generated changes safe to undo.

Beginner14 min read

Worth reading 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.

Terminal
$ git status                    # what has changed$ git add .                     # stage everything$ git commit -m "message"       # save a snapshot$ git push                      # send it to GitHub

And the one that makes the rest safe:

The undo
$ git restore .                 # throw away uncommitted changes

Branches 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.

Terminal
$ 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 experiment

This 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.

Commit 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.

  1. 1
    Weak

    “updates”, “fix”, “wip”, “changes from AI”

  2. 2
    Useful

    “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:

Prompt
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. 1

    Push your branch

    git push -u origin add-dark-mode

  2. 2

    Open the PR

    GitHub prompts you, or use gh pr create.

  3. 3

    Read the whole diff

    This is the review. Look for things you did not ask for as much as for bugs.

  4. 4

    Merge, then delete the branch

    GitHub offers both in one click.

When it goes wrong

  1. 1
    Committed something you should not have

    git reset --soft HEAD~1 undoes the commit and keeps the changes staged.

  2. 2
    Committed 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.

  3. 3
    Branch is a mess

    Switch back to main and delete it. That is what branches are for.

  4. 4
    Merge 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.
  • 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.
  • A committed secret must be rotated. Deleting the line does not remove it from history.