Guide

A safety net for AI coding: Git basics for non-coders

Learn the five Git commands that let you undo anything an AI tool does to your project. Works with Claude Code, Cursor or any other coding assistant.

Beginner 9 min read 24 Oct 2026 Claude CodeCursor

AI coding tools are fast, and sometimes that's the problem. A request like "tidy up the header" can quietly touch ten files, and by the time you notice something's off, you can't remember what the site looked like before.

Git is the fix. It's a free tool that keeps a history of your project, so you can save checkpoints and rewind to any of them. It works with every AI coding tool, including Claude Code and Cursor, because it works on your files directly.

You need only a handful of commands. This guide covers them in the order you'll use them.

Plain-English vocabulary

  • Repository (repo): a project folder that Git is tracking.
  • Commit: a saved checkpoint, like a "save game" with a note attached.
  • Working tree: your files as they are right now, including unsaved-to-Git changes.
  • Staging: choosing which changes go into the next commit.
  • Branch: a separate line of work, so experiments don't disturb your main version.

Step 1: Install Git and check it works

Open a terminal and type:

git --version

If you see a version number, you already have it. If not, download it from git-scm.com (on macOS, running git for the first time will usually offer to install it for you).

Tell Git who you are, once:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Step 2: Turn your project into a repo

In a terminal, go to your project folder and run:

git init

That's it. Git is now watching the folder. Many projects already have this done, particularly anything you downloaded from GitHub. To check, run git status. If it says "not a git repository", you need git init.

Don't track what you shouldn't

Some files shouldn't be saved in history: passwords, secret keys and bulky generated folders. Create a file named .gitignore in the project root listing them, one per line:

.env
node_modules/
dist/

.env files commonly hold secrets, node_modules/ is a large folder of downloaded code, and dist/ is build output. Git will skip anything listed. Do this before your first commit.

Step 3: Save a checkpoint (commit)

Before asking an AI tool to do anything big, save where you are:

git add .
git commit -m "Checkpoint before asking AI to redo the header"
  • git add . stages every change.
  • git commit -m "..." saves a checkpoint with a note. Write something your future self will understand.

This is the most important habit in this guide. Commit before you ask for a large change.

Step 4: See what the AI changed

After the AI has done its work, run:

git status

You'll get a list of files that changed, were added or were deleted. To see the exact lines, run:

git diff

Lines starting with - were removed and lines starting with + were added. You don't have to understand all of the code. Look for the surprising things:

  • Files you didn't expect to change.
  • Large deletions.
  • New files with odd names.

If the change looks right, commit it (Step 3 again). If it doesn't, go to Step 5.

Most editors, including Cursor, show the same information visually in a "Source Control" panel, with changed files listed and a side-by-side view. Use whichever you find easier.

Step 5: Undo what you don't like

This is the safety net. There are three levels of undo.

Undo one file

If the AI messed up a single file and you want it back as it was at your last commit:

git restore path/to/file

Careful: this throws away the changes in that file. There's no undo for the undo, so run git diff path/to/file first if you aren't sure.

Undo everything since your last commit

git restore .

This reverts every tracked file to your last checkpoint. Careful: any uncommitted edits you made yourself are thrown away too, and this can't be undone. New files the AI created aren't removed by this command. To see them, run git status (they appear under "Untracked files"), then delete them yourself, or run git clean -n to preview what would be removed (the -n means "dry run: just show me") and git clean -f to actually remove those files. Warning: git clean -f permanently deletes untracked files (they aren't in Git, so there is no way back), so only run it after checking the -n preview.

Undo a commit you've already made

If you committed something and regret it, the safest option is revert, which adds a new commit that cancels the old one out:

git log --oneline
git revert <commit-id>

git log --oneline lists your commits with short IDs. Pick the one to cancel and use its ID in the second command. History stays intact, which makes revert much harder to get wrong.

Step 6: Work on a branch for bigger experiments

For something adventurous, such as redesigning a page, work on a branch so your main version stays safe:

git switch -c redesign-homepage

Make your changes and commit as you go. If you love the result, merge it back. If not, switch back to your main branch and forget about it:

git switch main

(Depending on how the project was set up, the main branch may be called main or master. git branch lists yours.)

Your original work sits untouched on main the whole time.

Step 7: Back up on GitHub (optional but wise)

Git saves history on your computer. A free hosting service like GitHub keeps a copy online, which protects you if your laptop dies. Create an empty repository on GitHub, copy the commands it shows you for "push an existing repository", and run them. After that, git push uploads your latest commits.

A workflow that works with any AI tool

  1. Commit so you have a clean starting point.
  2. Ask the AI for one specific change.
  3. Check with git status and git diff, or your editor's source control panel.
  4. Test that your site or app still works.
  5. Commit if it's good, or restore if it isn't.
  6. Repeat.

Small loops keep every change easy to check and every mistake cheap to undo.

Tips for AI-specific pitfalls

  • Ask it to explain. A prompt such as "Summarise which files you changed and why" helps you review quickly.
  • Don't let it commit blindly. AI tools can write commits for you, but read the message and the diff before you accept.
  • Watch for secrets. If an AI tool adds a password or key to a file that's tracked by Git, remove it and change the password, because history remembers.
  • Never run commands you don't understand. Be especially wary of anything containing rm, --force or reset --hard. Ask the AI to explain a command before you run it.
  • Avoid doing two big things at once. If something breaks, you want to know which change caused it.

Common problems

"fatal: not a git repository". You're not in a repo folder, or you haven't run git init. Use cd to move to your project.

"nothing to commit, working tree clean". There are no changes to save. That's fine.

"Please tell me who you are". Run the two git config --global commands in Step 1.

I committed a secret by mistake. Treat it as compromised: revoke or change it immediately. Removing it from history is harder, so ask someone experienced if it's a real credential.

Cheat sheet

I want to...Command
Start tracking a foldergit init
See what changedgit status then git diff
Save a checkpointgit add . then git commit -m "message"
Undo one filegit restore path/to/file
Undo all uncommitted changesgit restore .
Cancel an old commit safelygit revert <commit-id>
Start an experimentgit switch -c branch-name
Go back to maingit switch main
See historygit log --oneline

Print that table. With it, you can hand an AI tool a whole project and always get it back the way it was.