Git, PRs, and Change Management

Use branches, commits, pull requests, and reverts so every AI-made change is small, reviewable, and easy to undo.

Content date: October 15, 2026.

Plain English

Git keeps a history of your project's files. A branch is a separate line of work. A commit is a saved snapshot of changes you chose. A pull request (PR) is a GitHub page showing a proposed change for review before it joins the main branch. Your folder may hold valuable unsaved work, so never throw it away for a tidy history.

Use this when

Do this before your first meaningful edit, and any time a change needs review, teamwork, or a way back.

If you are just starting

Before editing, run `git status` (lists changed files) and `git diff` (shows the exact lines). Start a branch with `git switch -c fix-contact-form`. Stage a file, meaning mark it for the next commit, with `git add` and its name. Run `git diff --staged` to see what the commit will hold, then `git commit -m "Fix contact form error"`.

When your project grows

On GitHub, protect your main branch so changes need a pull request and passing checks, using a ruleset (Settings, then Rules, then Rulesets) or older branch protection rules. As of October 2026, both work on public repositories on the Free plan and on private ones only with a paid plan. When branches conflict, decide by what the software should do, then test the combined result. Undo shared work with a revert commit, not a force push.

Worked example

You ask an agent to fix a contact-form error message. Git status shows the form file, plus a stylesheet your designer, Priya, changed but hasn't committed. The agent stages only the form file and its test, and leaves Priya's stylesheet alone.

Practice

A reviewable change and a safe undo

  1. Ask your AI tool to create a folder named git-practice with a small index.html, run `git init` (makes it a Git repository), and make a first commit. Then run `git switch -c practice-change`.
  2. Change the page heading in index.html. Run `git diff` (shows unstaged changes) and read it.
  3. Run `git add index.html`, then `git diff --staged`, then `git commit -m "Change the page heading"`.
  4. Write a three-line pull-request description: what changed, why, how you checked it.
  5. Run `git revert HEAD`, which adds a commit undoing the last one (save and close the editor if it opens). Confirm the old heading returns.

Deliverable: Your commit, your pull-request description, and `git log --oneline` output showing the revert.

Common mistakes to watch for

  • You run `git add .` and commit a .env file full of live keys.
  • A "clean up" reset erases a teammate's unsaved stylesheet changes.
  • Resolving a conflict by keeping one side deletes the other's feature.
  • Two branches pass tests alone, but the app breaks once both merge.

Prompting

A weak prompt

Clean up the repo, commit everything, and force push.

A better prompt

Run git status and git diff first and tell me what you see. Work on a new branch for this task only and leave unrelated files alone. Stage only your changes, show me git diff --staged, then commit with a plain message and summarize what changed and how you checked it. Explain any merge conflict and test the combined result. Never discard changes or force push unless I say so.

It keeps each change small enough to review and always leaves a way back.

Check before you move on

  • You ran git status before editing.
  • Unrelated files were left alone.
  • You read the staged diff before committing.
  • No passwords or .env files are committed.
  • You checked the new behavior works.
  • You practiced a revert on a practice branch.

You are done when

  • The commit contains exactly the change you intended.
  • You can revert it and see the old behavior return, without losing unrelated work.

Questions to think about

`git diff` looks fine, but you haven't run `git diff --staged`. Why does the second matter?

A commit holds only what is staged, so the staged diff catches a forgotten or accidental file.

Git status shows a modified file you never touched, and the agent offers to reset it "to keep things tidy." What do you say?

Leave it. It is probably someone's unsaved work, and a reset erases it for good.

A bad change is merged into the shared main branch. Why revert instead of force pushing it away?

A revert records the undo as a new step, so teammates stay in sync. A force push rewrites history under them.

Official references