Git & Environments for AI Coders
How your project goes from "I'm building this on my laptop" to "anyone in the world can visit my website." No coding knowledge needed: your AI tool handles the technical parts.
In this chapter
- How a project goes from your laptop to the live internet
- What Git, branches, and environments are for
- Why staging sites save you from embarrassing bugs
- How AI tools handle the technical workflow steps for you
The Big Picture
Think of this like writing a book: you write a draft on your computer, save your progress, back it up to the cloud, and then publish it for the world to read. Building a website works the same way.
What is Git (and Why Should You Care)?
Git is like save points in a video game. Every time you "commit" (save) your work, Git remembers exactly what your project looked like at that moment. If you break something, you can always go back to a previous save point.
GitHub is like cloud storage for your save points. It keeps a backup of your entire project history online, so you never lose your work, even if your laptop dies.
The good news: your AI tool handles all the Git commands for you. You just need to understand what's happening so you can tell it what you want.
Key Concepts in Plain English
Branches: Parallel Universes of Your Project
Imagine you're writing a novel. Your finished draft is safe in a folder. Now you want to try rewriting Chapter 3, but you're not sure if it'll be better. Instead of editing the original, you make a copy and experiment there.
That's exactly what a branch is. It's a copy of your project where you can try new things. If the experiment works, you merge it back into the original. If it doesn't, you just delete the copy. The original is never touched.
Common Branch Types
- Main The 'official' version. This is what your live website shows. You never experiment directly here: you always create a branch first, then merge back. Protected
- Feature branch Created when you want to add something new (like a navbar, a contact form, or a new page). One branch per feature keeps things organized. Per Feature
- Fix branch Created when you need to fix a bug. You make the fix in its own branch, test it, then merge it into main. Per Bug
What to tell your AI tool
“Create a new branch called feature/contact-form and switch to it”
“Save my current progress with the message 'Add contact form with email validation'”
“Upload my latest changes to GitHub”
“Switch back to the main branch”
“Merge my feature/contact-form branch into main”
Writing Good Save Point Descriptions
Every time you save a checkpoint (commit), you include a short message describing what changed. This helps you (and your AI tool) understand your project history later.
❌ Unhelpful Descriptions
- fix stuff
- update
- asdfasdf
- WIP
- changes
- final version
- final final version
✅ Helpful Descriptions
- Add responsive navbar with hamburger menu
- Fix login form validation on email field
- Update hero section gradient colors
- Add user authentication with Clerk
- Remove unused dependencies
- Redesign Card component with new variants
- Style pricing page for mobile screens
Environments: Your Project's Three Lives
Your project lives in three different places, each with a different job. Think of it like a restaurant: you test new recipes in the kitchen (development), have taste-testers try them (staging), and only then put them on the menu for customers (production).
Where you and your AI tool build things. Only you can see it.
- Lives on your computer only
- Changes appear instantly as you work
- Uses test passwords and fake data
- Errors show detailed messages to help you fix them
- Nothing here affects real users
A test version online. Share it with others to get feedback before going live.
- Vercel creates this automatically when you upload changes
- Each branch gets its own preview link
- Uses test data, not real customer data
- Share the link with friends or clients for feedback
- A safe way to see how things look 'for real'
The real deal. What your actual visitors and customers see.
- Only updates when you merge to the main branch
- Uses real data and real payment processing
- Errors are logged but not shown to visitors
- Performance and speed are monitored
- This is what people find on Google
Secret Keys and Passwords (Environment Variables)
Your project needs passwords, API keys, and secret codes to connect to services like databases, email senders, and payment processors. These are called environment variables, and they must be kept secret.
The Golden Rule
Never upload your secret keys to GitHub. They live in a special file on your computer (and in your hosting platform's settings), but they should never be included in your save points.
Your AI tool knows this rule, but it's worth understanding why: if your secrets end up on GitHub, anyone could find and use them, running up charges on your accounts or accessing your data.
🔒 Secret (Server-Only) Keys
These are passwords and keys that should never be visible to visitors. They only run on the server (the behind-the-scenes part of your website).
- Database password
- Payment processing key
- Login system secret
- Email service key
🌐 Public (Browser-Safe) Values
These are not secrets: they're values that the visitor's browser needs to know, like your website's URL or a public project ID.
- Your website URL
- Public database URL
- Public payment key
- Analytics ID
What to tell your AI tool
“I need to add my Stripe API key. Where do I put it so it stays secret?”
“Set up environment variables for my project so my database password doesn't get uploaded to GitHub”
“I just got an API key from Resend for sending emails. Help me add it to my project safely.”
Deploying with Vercel
Vercel is the most popular way to put a Next.js website online. Once set up, it's completely automatic: you upload your code, and Vercel publishes your website.
-
1
Connect your GitHub project to Vercel (one-time setup) Go to vercel.com, sign in with GitHub, and pick your project. This tells Vercel to watch for changes.
-
2
Add your secret keys in Vercel In your Vercel project settings, add the same secret keys you use on your computer. Vercel needs them to run your website.
-
3
Upload changes to any branch Every time you push code to GitHub, Vercel automatically builds a preview version with a unique link you can share.
-
4
Open a Pull Request Vercel adds a comment to your Pull Request with the preview link. You (or a friend) can check if everything looks good.
-
5
Merge to main When you merge your branch into main, Vercel automatically publishes the changes to your live website. That's it!
Files You Should Never Upload to GitHub
Some files and folders should stay on your computer (or on Vercel) and never be included in your Git save points. Your project has a special file called .gitignore that handles this automatically.
What to tell your AI tool
“Check my project and make sure none of my secret keys, installed packages, build files, or operating system junk files ever get uploaded to GitHub. Set things up correctly so only the files I actually want to share get pushed.”
Your Daily Workflow (Step by Step)
Here's what a typical day of building looks like, in plain English:
-
1
Start: Get the latest version If you're working with others (or made changes from another computer), this makes sure you have the newest version.Tell AI:
“Pull the latest changes from GitHub so I'm up to date”
-
2
Branch: Create a safe space to work This gives you a separate copy to experiment in. Your live site stays untouched.Tell AI:
“Create a new branch called feature/contact-form”
-
3
Build: Work with your AI tool Your AI tool makes the changes. You can see them live on your computer as you go.Tell AI:
“Add a contact form with fields for name, email, and message”
-
4
Save: Create a save point Save checkpoints often! If something breaks later, you can always go back.Tell AI:
“Save my progress with the message 'Add contact form with email validation'”
-
5
Upload: Back up to GitHub This uploads your work. Vercel will automatically create a preview link.Tell AI:
“Push my changes to GitHub”
-
6
Review: Open a Pull Request This is where you (or someone else) reviews the changes before they go live.Tell AI:
“Create a Pull Request to merge my contact form into the main branch”
-
7
Ship: Merge and go live Merge the Pull Request on GitHub (click the green button). Vercel automatically publishes your changes to your live website. Done!
Automatic Testing and Publishing
When you upload code to GitHub, some behind-the-scenes checks can run automatically. This is called CI/CD (don't worry about the name, just think of it as "automatic quality checks + automatic publishing").
Automatic Quality Checks
When you upload code, these checks can run automatically to catch mistakes:
- Checks for common coding errors
- Makes sure your project can still build without breaking
- Runs any tests you've set up
- Blocks merging if something is wrong (protects your live site!)
Automatic Publishing
After the checks pass, your website is published automatically:
- Upload to any branch = preview link for testing
- Merge to main = your live website updates
- Vercel handles this for you (no setup needed)
- If the build fails, your live site stays as-is (safe!)
Common Problems (and What to Tell Your AI Tool)
Things go wrong sometimes, and that's totally normal! Here are the most common issues and exactly what to say to your AI tool to fix them.
“I accidentally committed to the wrong branch. Move my last commit to [correct branch name] instead.”
“Undo my last commit but keep the changes so I can re-do it differently.”
“I have merge conflicts. Help me resolve them. I want to keep [describe which changes you prefer].”
“I accidentally committed my .env file with secret keys. Remove it from Git history and make sure it's in .gitignore.”
“My branch is behind main. Update it with the latest changes from main.”
“Delete node_modules and the lock file, then reinstall everything fresh.”
Frequently Asked Questions
Do I need to memorize Git commands?
Not at all! Your AI tool (Claude Code, Cursor, etc.) handles all the Git commands for you. You just need to understand the concepts (like what a branch is or why you save checkpoints) so you can tell your AI tool what you want in plain English.
What happens if I break my website?
That's what branches are for! If you always work in a branch (not directly on main), your live website is safe. And even if something does go wrong, Git remembers every save point: you can always go back to a working version.
How often should I save (commit)?
Save often: every time you finish a small, working piece. Added a new section to a page? Save. Fixed a styling issue? Save. Think of it like saving a document: you wouldn't write 10 pages without hitting save.
Do I need GitHub AND Vercel?
GitHub stores your code and its history (like a cloud backup with time travel). Vercel takes that code and turns it into a live website. They work together: you upload to GitHub, and Vercel automatically publishes from there.
What if I'm the only person working on this? Do I still need branches?
Branches are still helpful even solo! They let you experiment safely. If you're trying something risky (like a complete redesign), a branch means you can always abandon the experiment and go back to what was working.
My Vercel deploy failed. What do I do?
Tell your AI tool: "My Vercel deploy failed. Here's the error message: [paste the error]." Vercel shows build logs with specific error messages. Sharing those with your AI tool is the fastest way to get a fix.
What's the difference between Git and GitHub?
Git is the system that creates save points and tracks your project history. It runs on your computer. GitHub is the website where you store a backup of that history online. Think of Git as your camera and GitHub as your photo album in the cloud.