Skip to content
Visual explainer 3h to learn 5 steps

The Git loop for small AI-assisted changes

Read the working tree, create a branch, review the assistant's plan, make one bounded edit and inspect the diff before committing.

By Invicly Tech, , in Prompt Engineering and Vibe Coding. About 8 minutes to read.

Topic 9 of 29

In short

Git records every change, so you can undo mistakes. For AI-assisted work, a safe loop is: look at the state of the repo, make a branch, read the assistant's plan, allow one small edit, then read the diff before you commit.

Think of it like this: A branch is a photocopy of your notes: scribble on the copy, check it, and only then merge it into the original.

Explained simply

Git is a tool that remembers every version of your project. If an AI assistant breaks something, Git lets you go back. That safety is why Git matters more, not less, when an assistant writes code.

You use Git from the terminal, a text window where you type commands. A few basics are enough: pwd shows where you are, ls lists files and cd moves into a folder. Then git status tells you what has changed.

Before you ask for a change, create a branch with git switch -c and a short name. A branch is a safe copy of the line of work, so your main branch stays clean.

Ask the assistant for its plan first and read it. Allow one small edit. Then run git diff and read every changed line. Commit only when the diff matches what you asked for.

Press Play on a diagram to walk through it one step at a time.

CycleThe small-change loop
  1. 1
    Read state

    git status and git log --oneline

  2. 2
    Branch

    git switch -c my-change

  3. 3
    Plan

    Read the assistant's plan first

  4. 4
    One edit

    Allow one bounded change

  5. 5
    Diff

    git diff, then commit if good

  6. Back to step 1
MapWhere your change lives
Repository
  • main branch
    • Stable, reviewed code
  • your branch
    • Assistant edits happen here
    • Safe to discard
  • working tree
    • Files on disk right now
    • Shown by git status

In depth

Basic terminal commands

The terminal accepts short commands. pwd prints the folder you are in. ls lists its files. cd folder-name moves into a folder, and cd .. goes up one level. Nothing here changes your files, so they are safe to practise. Commands run in the current folder, which is why pwd is the first thing to check when something behaves oddly. On Windows you can use PowerShell, where ls and cd work the same way and pwd also works.

  • pwd: where am I
  • ls: what is here
  • cd name: go into a folder
  • cd ..: go up one level

Reading the state of the repo

git status shows which files you changed, which are ready to commit and which are new. git log --oneline shows recent commits, one line each, so you can see the history and the last commit message. Run both before you start. A clean status means you are safe to begin. If it shows unexpected changes, find out why before adding more, because the assistant's edits will mix with them and be hard to separate.

  • git status: current changes
  • git log --oneline: recent history
  • Start from a clean status
  • Explain unexpected changes first
SequenceA safe round trip with the assistant
You
Terminal
Assistant
  1. 1git status, git switch -c new-branch
    You to Terminal: git status, git switch -c new-branch
  2. 2Ask for a plan, no edits yet
    You to Assistant: Ask for a plan, no edits yet
  3. 3Plan and files it will change
    Assistant to You: Plan and files it will change
  4. 4Approve one edit
    You to Assistant: Approve one edit
  5. 5git diff
    You to Terminal: git diff
  6. 6git commit if the diff is right
    You to Terminal: git commit if the diff is right

Reviewing the diff and undoing

git diff prints lines removed with a minus and lines added with a plus. Read all of it. Look for files you did not expect, deleted code, and changes in settings or dependency files. If one file is wrong, git restore path discards its unsaved edits. If the whole branch went wrong, go back with git switch main and delete the branch later. Because the work was on a branch, main was never at risk. Commit often, with a message that says what changed.

  • Minus lines are removed, plus lines are added
  • Look for surprise files
  • git restore path discards unsaved edits to a file
  • git switch main leaves the branch behind

Learn it in 5 short steps

About 35m each. Track them with a timer in your plan.

  1. 1
    Learn the basic terminal commands~35m
  2. 2
    Read git status and the log~35m
  3. 3
    Create a branch with git switch~35m
  4. 4
    Review the plan before any edit~35m
  5. 5
    Inspect git diff before committing~35m

Key points

  • git status shows what changed. Run it before you start and after each edit.
  • git log --oneline lists recent commits in short form.
  • git switch -c name creates a branch and moves onto it, so main stays untouched.
  • Review the assistant's plan before it edits any file. A wrong plan is cheaper to fix than wrong code.
  • git diff shows exact line changes. Read it before every commit.

Key terms

Tap a card to flip it. 0/5 known

Examples

bash
pwd                      # where am I?
ls                       # what is here?
git status               # clean? any changes?
git log --oneline -5     # last five commits
git switch -c add-level-filter
# ask the assistant for a plan, then one edit
git diff                 # read every changed line
git restore src/App.tsx  # undo a file if the edit is wrong

Needs Git installed and a folder that is a Git repository. git restore discards unsaved edits to that file, so use it only when you want them gone.

A first small change, with rollback

Prerequisites: Git installed and a project folder that is already a repository. Steps: check status, make a branch, let the assistant make one edit, then read the diff. You should see status say working tree clean at the start, and a diff limited to one file at the end. To roll back, restore the file or switch back to main.

bash
git status                     # expect: nothing to commit
git switch -c fix-button-label
# ask for a plan, approve one edit
git diff                       # expect: one file, a few lines
git commit -am "Fix button label"
# rollback instead of commit:
# git restore src/Button.tsx
# git switch main

Catching a surprise in the diff

You asked for a text change in one file. The diff shows a second file, package-lock.json, with hundreds of changed lines. That means the assistant installed something. You did not ask for that, so you restore the lockfile and the dependency file and ask again with a rule to add no packages.

bash
git diff --stat
#  src/Button.tsx     |   2 +-
#  package-lock.json  | 412 ++++++
git restore package-lock.json package.json

Quick reference

  • pwd shows the folder; ls lists files; cd moves.
  • git status shows changed files.
  • git log --oneline lists recent commits.
  • git switch -c name creates and enters a branch.
  • git diff shows the exact line changes.
  • git restore path discards unsaved edits to a file.
  • Read the plan before allowing any edit.

Common mistakes

  • Letting the assistant edit many files at once, which makes the diff too big to review.
  • Committing without reading the diff, so stray changes slip in.
  • Working directly on main, which leaves no easy way back.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which command creates a new branch and moves to it?

Question 2

2What does a line starting with a plus mean in git diff?

Question 3

3Why review the assistant's plan before it edits?

Question 4

4git status shows five unexpected changed files before you start. What next?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    In a practice repository, run the commands that show your folder, its files and the repo state.

  2. Exercise 2medium

    Create a branch called practice-edit, change one line of a README by hand, and view the change.

  3. Exercise 3hard

    You asked an assistant for a one-file change, but git diff --stat shows four files. Write the steps you take.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I need to learn the terminal for vibe coding?
A few commands are enough: pwd, ls, cd and the Git commands here. Many editors also have buttons for Git, but the terminal shows exactly what happens.
What if I run git restore by mistake?
Unsaved edits to that file are gone and cannot be recovered by Git. Commit often so less work is at risk.
Why a branch instead of main?
A branch keeps main stable. If the change goes wrong, you drop the branch and nothing is lost.

Go deeper

ShareXLinkedInWhatsApp