Skip to main content

Version Control Basics

If you're building apps with AI, you've probably experienced this:

You ask the AI to make a change. It works. Then you ask for another change. Something breaks. You ask it to undo the last change — but now the AI has lost context, and the fix it gives you is different from what you had before. You can't get back to the working version.

This is where version control saves you.

What Is Version Control?

Version control is a system that tracks every change you make to your code over time. Think of it like a save button for your entire project — but better, because you can:

  • See exactly what changed between versions
  • Go back to any previous version
  • Work on multiple features at the same time without them interfering
  • Keep a backup of your code outside your computer

The most common version control system is Git, and the most popular place to store Git repositories online is GitHub.

Why Version Control Matters for AI-Assisted Development

When you're using AI to generate code, version control becomes even more important:

ProblemHow Version Control Helps
AI generates code that breaks somethingRoll back to the last working version instantly
AI loses context and gives different resultsYou keep every version, so you can restore the good one
You want to try a risky changeCreate a branch, experiment safely, and merge if it works
You accidentally delete or overwrite filesGit keeps the history — nothing is truly lost
You need to share your project with someonePush to GitHub and they can see everything

The Core Concepts

Repository (Repo)

A repository is a folder that Git is tracking. It contains all your project files plus the entire history of changes.

Commit

A commit is a snapshot of your project at a specific point in time. Each commit has a message describing what changed and why.

Think of commits like save points in a video game. You can always go back to any save point.

Branch

A branch is a separate line of development. The main branch (usually called main or master) is your stable, working version. You create other branches to work on new features or experiments without touching the main code.

main: ──── A ──── B ──── C ──── D
\
feature: E ──── F ──── G

When the feature is ready, you merge it back into main.

Remote

A remote is a copy of your repository stored on another computer — usually a service like GitHub, GitLab, or Bitbucket. This gives you a backup and makes it easy to collaborate.

Getting Started With Git

Step 1: Install Git

Download and install Git from git-scm.com. On macOS, you can also install it via Homebrew:

brew install git

Step 2: Configure Git

Open your terminal and set your name and email (this gets attached to your commits):

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

Step 3: Create a Repository

Navigate to your project folder and initialize a Git repository:

cd your-project-folder
git init

Step 4: Make Your First Commit

# Add all files to the staging area
git add .

# Create a commit with a message
git commit -m "Initial commit"

Step 5: Connect to GitHub

  1. Create a free account at github.com
  2. Click the + icon → New repository
  3. Follow the instructions to push your existing repository:
git remote add origin https://github.com/your-username/your-repo.git
git branch -M main
git push -u origin main

A Simple Workflow for AI-Assisted Development

Here's a practical workflow that works well when you're using AI to generate code:

1. Start on the main branch

Your main branch should always contain working code.

2. Create a branch for each feature or fix

git checkout -b add-login-page

3. Ask the AI to generate code

Let the AI do its work in this branch. If the result is good, commit it. If it's bad, you can throw the branch away without affecting anything.

4. Commit after each successful AI interaction

git add .
git commit -m "Add login page with email and password fields"

This creates a save point you can always return to.

5. Test the result

Make sure the generated code actually works before merging.

6. Merge back to main

git checkout main
git merge add-login-page

7. Push to GitHub

git push origin main

What to Commit

A good rule of thumb: commit after every meaningful change. This includes:

  • A new feature or page generated by AI
  • A bug fix
  • A configuration change
  • Updated documentation

Each commit message should explain what changed and why:

Good: "Add password reset flow with email verification"
Bad: "fix stuff"

What NOT to Commit

Some things should never be committed to version control:

  • API keys, passwords, or secrets — use environment variables instead (see API Keys & Secrets)
  • Large generated files — like node_modules or build outputs
  • Personal configuration files — like .env or IDE settings

Git uses a file called .gitignore to automatically exclude these. Here's a good starting .gitignore:

node_modules/
.env
.env.local
dist/
build/
.DS_Store
*.log

Common Git Commands Cheat Sheet

CommandWhat It Does
git initCreate a new repository
git add .Stage all changes for commit
git commit -m "message"Save the staged changes
git statusSee what files have changed
git logView commit history
git checkout -b branch-nameCreate and switch to a new branch
git checkout branch-nameSwitch to an existing branch
git merge branch-nameMerge a branch into the current one
git pushUpload commits to GitHub
git pullDownload latest changes from GitHub
git diffSee what changed in unstaged files

What If You're Not Using Git?

If you're not using version control yet, here's what you're risking:

  • Losing working code — one bad AI prompt and you can't get back
  • No undo — every change is permanent
  • No backup — if your computer dies, your project dies with it
  • No history — you can't see what changed or when

The good news is that setting up Git takes about 10 minutes, and it will save you hours of frustration.

Version Control and AI: A Perfect Pair

AI tools generate code quickly. Version control lets you experiment fearlessly:

  • Try a bold change in a branch. If it works, merge it. If it doesn't, delete the branch.
  • Ask the AI to refactor a feature. If the result is worse, roll back to the last commit.
  • Compare different AI-generated approaches side by side in different branches.

Version control gives you the freedom to experiment with AI without the fear of breaking everything.

Next Steps

  • Set up Git on your current project (it's never too late)
  • Create a GitHub account and push your first repository
  • Make it a habit to commit after every successful AI interaction
  • Learn more about branching strategies as your project grows

For a deeper dive, check out GitHub's Getting Started Guide.