Git for AI 1, the basics
Why you need Git the moment you start building with Claude or Cursor. And how to be set up in 15 minutes.
What this is about
Imagine you let Claude build a small web app. It works, you make a small change, want a second feature, and suddenly everything is broken. Login fails, a file is gone, you do not know why.
Without Git you now spend an hour trying to piece this back together. With Git you type one command and you are back at the working state in one second.
That is the entire point of Git in this course. Not "version control for software teams." But a safety net for you when you build with AI and the AI was once again faster than your brain.
The save-game metaphor
If you played video games as a kid, you saved before a hard boss fight. If the fight went sideways, you loaded the save and tried again. If it went well, you saved a new state and moved on.
Git works the same way.
- A commit is a save state.
- A repository (repo) is your full save folder.
- GitHub is cloud backup for your saves, plus you can share them with others.
That is all you need to understand to start.
Why this matters more for AI
When you type yourself, you make maybe ten changes an hour. You roughly remember what you changed where.
When Claude Code runs a single task, it sometimes touches eight files at once. Refactor here, new function there, an import line somewhere. If something breaks afterwards, the editor undo cannot save you, because that only works per file and only inside the current editor session.
With Git that is fine. You commit before each bigger AI task, and if the task goes wrong, you are back at the previous state in one second.
The sentence that captures this best comes from a blog post on AI coding. AI tools work at a speed where the cost of a mistake scales with the speed of the AI. The faster the AI, the more damage one bad prompt can do without version control. Git is the seatbelt that makes fast driving survivable.
What to install now
You need two things.
-
Git itself. The software running in the background.
- Mac:
brew install gitorgit --versionto check if you already have it. - Windows: download from git-scm.com, default installer.
- Linux:
sudo apt install gitor your distro equivalent.
- Mac:
-
A GUI as your starting point. You will learn the command line later. For the start, a graphical interface is enough, it shows you what you are doing.
- GitHub Desktop (desktop.github.com), free, very beginner friendly.
- Or VS Code Source Control Tab if you already use VS Code.
Both are enough for everything in this mini-module. I recommend GitHub Desktop for the start, less distraction than a full editor.
Create a GitHub account
Sign up on github.com, free. Choose a username, confirm your email. You will need the username later, so pick one you would put on a business card.
Your first repo
In GitHub Desktop top left "File" then "New Repository". Give it a name, pick a location, check "Initialize with README". Click "Create".
You now have a local repo. There is a folder on your disk, inside is a README.md.
Make a small change to the README. Type "Hello world" or something. Save.
In GitHub Desktop you now see the file with a yellow dot on the left. That means: changed but not committed. Bottom left there is a commit message field, type "first change", click "Commit to main".
First save state is in.
Push to GitHub
Now you want the repo visible on github.com as backup. Top of GitHub Desktop says "Publish repository". Click it, check "Keep this code private" (get used to private as your default), "Publish".
30 seconds later your repo is on github.com/YOUR-USERNAME/YOUR-REPO. You can browse it, the README is there.
Your new default workflow
From now on this is your routine before any Claude or Cursor session:
- If you do not have a repo yet, create one as above.
- Before the AI task: if anything is unsaved, commit it. Write a short message about what you had.
- Let the AI build.
- Check if it works. If yes: commit with a short description.
- If it does not work and is not fixable in 5 minutes: in GitHub Desktop or VS Code click "Discard all changes". You are back at the last commit.
These five steps are the entire trick. You do not need more for Lesson 1.
What you can do now
- Understand why Git is mandatory for AI code, not just recommended
- Install Git and GitHub Desktop
- Create a repo, commit, push to GitHub
- Discard changes when the AI broke something
Lesson 2 is about branches. The trick that gives the AI its own sandbox for each task without touching your working project.