Skip to content
Git

Git Basics for AI-Assisted Coding

Git isn't optional once an AI tool is editing your code for you — it's the only reliable way to review, commit and roll back changes.

Beginner8 min read

Why Git matters more, not less, with AI

When you write every line yourself, you remember roughly what changed. When an AI agent edits five files in ten seconds, you don't — and you have no way to prove it, or undo it cleanly, without version control. Git is what turns "I hope that was fine" into "I can see exactly what changed and revert it in one command."

Step 1: Initialize a repository

terminal
git init
git add .
git commit -m "Initial commit"

Step 2: Set up a .gitignore before your first commit

Do this before committing, not after — once secrets or dependency folders are committed, removing them from history is a much bigger job.

.gitignore
node_modules/
.env
.env.local
.next/
dist/
*.log

Step 3: Commit after every AI-driven change, not once a day

Small, frequent commits give you fine-grained rollback points. If an AI tool makes three changes in a row and the third one breaks something, you want to be able to go back to exactly after the second one — not to the start of your afternoon.

terminal
git add .
git commit -m "Add pricing page generated with AI, reviewed and tested"

Step 4: Review the diff before you trust it

This is the single most important habit in this tutorial. Reading a diff takes thirty seconds and catches problems before they're committed — reading them after they've broken production takes much longer.

terminal
git diff
git diff --staged   # after you've run `git add`, to see what's about to be committed

Step 5: Use branches for anything you're not sure about

terminal
git checkout -b feature/pricing-page
# make changes with your AI tool, commit as you go
git push -u origin feature/pricing-page
# open a pull request to review the full diff before merging to main

Step 6: Undo a bad AI change

  • Uncommitted changes you don't want: `git restore .`
  • One specific file: `git restore path/to/file.ts`
  • Undo the last commit but keep the files as they are: `git reset --soft HEAD~1`
  • Undo the last commit completely, discarding the changes: `git reset --hard HEAD~1` (only when you're certain)

Step 7: Connect to GitHub

terminal
git remote add origin https://github.com/yourname/your-repo.git
git branch -M main
git push -u origin main

Ready to build the next one?

Browse the full tutorial library or grab a ready-made prompt for your next step.