Free guide
Version control is a saved history of your project, and Git is the most widely used tool for keeping it. When an AI tool changes several files at once, Git shows exactly what changed, keeps what works, and takes you back to the last good version.
Quick principle: Treat AI output as a draft that earns trust through review, testing, and evidence. A commit is where you record that evidence.
What the terms mean
You only need a few words to start. Each one names something you may already do by hand, like saving copies named project-final-v2.
- Repository (repo): a project folder that Git is tracking, plus its full history.
- Commit: a named snapshot of the project at one moment, with a short message saying what changed and why.
- Diff: the line-by-line difference between two versions: what was added and what was removed.
- Staging: choosing which changes go into the next commit, so you can save one fix without including an unrelated experiment.
- Branch: a separate line of work. You can try a risky feature on a branch while the main line stays working.
- Remote: a copy of the repository stored somewhere else, such as a private GitHub or GitLab repository. It gives you an off-computer backup and a way to share work.
Why a beginner should care
An AI tool can rewrite more code in one reply than you can review in an hour. Without version control, one bad request can quietly break a feature that worked yesterday. With Git, every working state has a name, every change can be inspected, and recovery is a command, not a rebuild.
That is why earlier lessons keep saying “save the working version.” In Build and Verify the First Useful Slice, you build one thin slice at a time. Git turns each tested slice into a checkpoint you can return to.
Set up once before your first commit
Install Git from git-scm.com. Git attaches a name and email to every commit and may refuse to commit until both are set, so type these two lines in a terminal once, with your own details:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Anyone who can see the repository can see that email. On GitHub, turning on “Keep my email addresses private” gives you a noreply address (ID+username@users.noreply.github.com) to use instead.
You can use the command line or a visual app such as GitHub Desktop or the Source Control panel in VS Code. Both create the same history, so pick the one you can use comfortably.
A small worked example
Say you have a simple priority-list tool in a folder, and you open a terminal in that folder.
- Start tracking: run
git init. Git creates a hidden history folder. Your own files are not changed. - Keep secrets out first: create a file named
.gitignoreand list files that must never enter the history, such as.env. Do this before the first commit:.gitignoredoes not affect files Git already tracks. - Save the first working version: run
git add .(the dot means everything in this folder), thengit commit -m "Add task and show list", where-madds the message. - Ask the AI for one change, for example “add a due-date field.”
- Look before you keep it: run
git statusto see which files changed or were added, thengit diffto read the changes line by line. Brand-new files appear ingit statusbut not ingit diff. - Test it. If it works, commit again with a clear message. If it does not, run
git restore .to discard uncommitted edits to tracked files.
Here are the same commands in order. The AI makes its change between the commit and git status.
git init
git add .
git commit -m "Add task and show list"
git status
git diff
git log --oneline
git log --oneline lists your commits, newest first, one per line. That list is a plain-English diary of the project and useful context for your next AI session.
Undo without making things worse
Pick the gentlest undo that fits the situation.
- Edits you have not committed yet:
git restore .puts tracked files back. It does not delete brand-new files the AI created;git statuslists those as untracked, so review and remove them yourself. - A commit you already saved:
git revert --no-editplus the commit’s short ID (fromgit log --oneline) undoes it with a new commit, so nothing is erased. Without--no-edit, Git opens a text editor for the message. - Commands to avoid as a beginner:
git reset --hardandgit push --forcecan permanently erase work. If an AI tool suggests either one, stop and ask it to explain why a safer option will not work.
Common failure modes
- Giant commits: one commit called “updates” that mixes five changes. Commit after each tested slice instead, so each step can be undone on its own.
- Committing without reading the diff: the AI may have edited files you never asked about.
- Committing a secret: deleting a key in a later commit does not remove it from history. If a password or API key was ever committed, especially to a remote, treat it as exposed and replace it.
- Treating Git as your only backup: Git tracks your project files, not your live database, user uploads, or hosting settings. Those need their own backups; see Prepare a Reliable Deployment and Recovery Path.
The human review boundary
Let the AI draft code and even suggest a commit message. You decide what gets committed and pushed. Before each commit, ask the AI to list every file it changed and explain each change in one sentence, then compare that summary with the actual diff. If they disagree, stop and investigate. This habit pairs with the evidence-first approach in Test, Debug, and Prove the Important Journeys.
Safety and accessibility checks
.gitignorelists.env, key files, exported customer data, and local backups before the first commit.- Any remote repository for client or business work is set to private.
- Commit messages describe the change in words, such as “Fix blank-task error message,” so anyone, including screen reader users, can follow the history without opening code.
- Your interface works the way you use a computer. The command line gives plain text that screen readers read line by line; visual tools suit people who prefer buttons. Test yours with your own setup. Diffs mark added and removed lines with plus and minus signs, so you do not need the red and green colors.
- You have practiced one recovery, discarding an uncommitted change, before you actually need it.
Practical next step
- Choose one small project you are building with AI.
- Add a
.gitignore, rungit init, and commit the current working version. - Ask the AI for one change, read
git diff, and test ordinary, edge, keyboard, and recovery paths. - Commit if it works, or practice
git restore .if it does not, and note what happened.
Official sources and verification date
- Pro Git book: About Version Control
- Pro Git book: First-Time Git Setup
- Git documentation: gitignore
- Git documentation: git diff
- Git documentation: git restore
- Git documentation: git revert
- GitHub Docs: Email addresses reference
Sources checked October 23, 2026. Commands and defaults can change between Git versions, so check the documentation for your version.
Remember: Do not paste passwords, private customer information, API keys, payment data, or other secrets into an AI prompt. Obtain qualified review when failure could materially harm people.