Imagine AI just rewrote your entire authenticationWhat is authentication?Verifying who a user is, typically through credentials like a password or token. component. It looks good at first glance, but after testing you realize the old version handled edge cases better, and you already saved over it. If only you could go back in time...
That's exactly what Git does. It's a version control system that tracks every change, yours and AI's, creating snapshots you can return to whenever you want. When you're building with AI, Git isn't optional. It's your undo button for every AI-generated change that doesn't work out.
Why Git matters more when AI writes your code
Without Git, accepting an AI suggestion is a one-way door. With Git, every AI-generated change is reversible. You can try AI's approach, compare it against what you had, and roll back in seconds if it's worse.
Never lose work again
When you use Git, every significant version of your code is preserved. Accidentally deleted your database migrationWhat is migration?A versioned script that changes your database structure (add a column, create a table) so every developer and server stays in sync. script? No problem, just rewind to yesterday's commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed.. Changed your mind about that refactor? Revert it with one command.
Review AI changes before they stick
When AI generates a large code block, you need to review it line by line before it becomes permanent. Git's diffWhat is diff?A comparison showing exactly which lines were added, removed, or changed between two versions of code. tools let you see exactly what AI changed, compare it against your previous version, and selectively accept or reject parts of the output.
Git also enables branches: separate timelines where you can test AI-generated changes in isolation. If the AI's approach works, merge it. If it doesn't, delete the branch. Your main code stays untouched throughout.
Experiment fearlessly
Want to try rewriting your authenticationWhat is authentication?Verifying who a user is, typically through credentials like a password or token. system? Go ahead, create a branch. If it works, merge it. If it doesn't, delete the branch and pretend it never happened. Your main code stays untouched and stable throughout.
The AI trap: committing too often or not enough
AI coding assistants like Copilot and ChatGPT sometimes encourage bad Git habits. They might suggest committing after every single line change, creating a noisy, unreadable history. Or they do the opposite, generate a mountain of code and leave you with one giant commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. labelled "Add features."
git add . && git commit -m "update" after every prompt. This creates a commit history full of meaningless messages. Instead, commit when you reach a logical milestone, a working feature, a fixed bug, a completed refactor. Quality over quantity.| Habit | What AI suggests | What you should do |
|---|---|---|
| Commit frequency | After every prompt | After each logical milestone |
| Commit messages | "update", "fix", "changes" | Descriptive: "Add login form validation" |
| Staging | git add . every time | Stage selectively with git add filename |
| Review before commit | Skip it | Always run git diff --staged first |
The three areas you need to understand
Git's workflow revolves around three distinct areas. Understanding this flow is crucial, it's the foundation everything else builds upon.
Working directory: where you actually code
This is simply your project folder on your computer. When you open VS Code and edit app.js, you're working in the working directory. Git is watching these files, but it hasn't saved any changes yet.
Staging areaWhat is staging area?A holding zone in Git where you place changes you want to include in your next commit, letting you select exactly which modifications to save.: your pre-flight checklist
Before saving a snapshot (commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed.), you use git add to select which changes you want to include. Think of staging like packing a suitcase, you try on different outfits (edit files), decide what to bring (git add), and only then zip it up (commit).
RepositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory.: your project's memory
Once you run git commit, Git permanently stores your staged changes in the repository (specifically, in the hidden .git folder). This snapshot now has a unique ID, timestamp, and your message describing what changed.
Here's how it all flows together:
Working Directory → Staging Area → Repository
(edit files) (git add) (git commit)| Area | What's happening | Git command |
|---|---|---|
| Working Directory | You're actively editing files | None, just code! |
| Staging Area | Preparing changes for the next snapshot | git add filename |
| Repository | Permanent storage of all saved versions | git commit -m "message" |
Git and GitHub: not the same thing
This confusion trips up every beginner, so let's clear it up right now.
Git is a command-line tool that lives on your computer. It tracks changes, creates commits, and manages branches, all locally. You can use Git for years without ever touching the internet.
GitHub is a website (owned by Microsoft) that hosts Git repositories online. It's like Dropbox or Google Drive, but specifically designed for code. GitHub adds features like pull requests, issues, and wikis, but at its core, it's just storing your Git repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory..
You can use Git without GitHub, and you can even use GitHub without fully understanding Git (though I don't recommend it). But together, they're the industry standard for modern software development.
Why Git matters more with AI
If you're using AI to generate code, Git is non-negotiable. Here's why it's even more critical in an AI-assisted workflow:
- Reversibility: AI suggestions are experiments. Git lets you try them and roll back instantly.
- Diffing:
git diffshows you exactly what AI changed, line by line. This is your primary review tool. - Selective commits: AI often changes more than you asked for. Git lets you commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. only the parts you want.
- History: When AI-generated code breaks something three days later,
git logandgit bisecthelp you find exactly which change caused it.
Every AI-assisted project should be a Git repositoryWhat is repository?A project folder tracked by Git that stores your files along with the complete history of every change, inside a hidden .git directory. from the first prompt.
Quick reference
| Command | What it does | When to use it |
|---|---|---|
git --version | Check if Git is installed | First time setup |
git config --global user.name "You" | Set your identity | Once per machine |
git config --global user.email "you@email.com" | Set your email | Once per machine |
git config --list | View current config | Verify settings |
# Check if Git is installed
git --version
# Configure your identity (do this once)
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
# Check your configuration
git config --list