VibecodingChoosing tools & stackLevel 2: Context

How Do You Set Up Git, Previews and Tests for AI Coding?

Set up three safety nets before you build much. Git keeps every version, so you can go back. A preview shows each change on a temporary address before it goes live. A few automated tests tell you when a change breaks something you've already checked. It takes under an hour, and your tool does most of it.

Prompt to copy
Set up the safety nets for this project. Explain each step in plain language as you go.

1. Git: make sure a repository exists. Confirm .gitignore covers .env files, node_modules and build output. If any .env file is already tracked, stop and tell me, because it must be untracked and its keys rotated.
2. Tests: install Playwright with `npm init playwright@latest`, and write three tests of what matters most in this app:
   - a visitor can reach the home page
   - a user can [the main action, such as sign in and create a record]
   - a signed-out visitor is refused when requesting [a protected page or API route]
3. Commands: tell me the exact command to run all tests, and add it to [AGENTS.md / CLAUDE.md].
4. Rule: from now on, run the tests after every change, and tell me the result before saying the work is done.

Use test accounts from environment variables, never real credentials in the code. Don't use my production database for tests. Tell me what I must set up by hand.
  1. 1GitA copy of every version, outside your tool
  2. 2PreviewsSee each change before it goes live
  3. 3TestsRe-check yesterday's work on each change
Rule of thumb, drawn from Vercel, Lovable and Claude Code docs. Each net catches a failure the others miss.
  • Labeled AI co-authored10.83
    320 pull requests
  • Labeled human6.45
    150 pull requests
Average issues per pull request, from 470 open-source pull requests. Source: CodeRabbit, December 2025. CodeRabbit sells AI code review, used its own taxonomy, and can't guarantee the human-labeled ones were human only.

Try it now

  1. 1Connect Git. In Lovable, use Project settings → Git. In v0, use Project menu → Settings → GitHub, then Connect. In Replit, open the Git pane. Confirm the code appears on GitHub.
  2. 2Make a small change on a new branch. On Vercel, this creates a preview deployment with its own address, and your production site doesn't change.
  3. 3Paste the prompt above, then run npx playwright test, or npx playwright test --ui to watch it work. Break something on purpose. It worked when a test goes red.

Use it when

On day one for Git, and before your first real user for tests. Add a preview environment before you make changes to an app people already rely on.

Skip it when

Don't write tests for every button on a prototype you may throw away, since the design is still changing. Skip a separate staging environment until you have real users. Previews are usually enough before then.

Why it works

Each one catches a different failure. A builder's own history may not cover what you expect: Lovable's revert restores code but leaves data as it is. Git gives you a copy you own, outside the tool. On Vercel, each branch or pull request gets its own preview address, and production stays untouched until you merge.

Tests matter most because AI changes can reach further than you asked. A test re-checks yesterday's work automatically, including the parts you wouldn't think to click again. Anthropic's Claude Code guide says to give Claude a check it can run, so it can catch and correct its own mistakes rather than handing them to you.

Example

A membership app has a sign-up page and a members area. The three tests are: the home page loads, a test user can sign in and see the members area, and a signed-out request to the members area gets refused. A week later, you ask the AI to redesign the navigation. The third test fails because the redesign moved the sign-in check. Without the test, this would have stayed hidden, since you're always signed in when you look at the site yourself.

Going further

Know what "publish" does in your tool. v0 works on a separate branch, but Publish creates or reuses a pull request and merges it into your base branch. If you want a human gate, protect that branch. GitHub's branch protection can require pull requests and passing status checks before a merge. Lovable syncs one branch at a time, so commits on other branches don't appear until you merge them.

Previews and staging can share your real data if you let them. Vercel warns that staged production deployments use production variables, so testing can reach production services. Give previews their own values under Preview environment variables, and consider Supabase branching, which gives each branch its own database. Data isn't copied by default, so the branch starts without your real records.

If .env was committed, git rm --cached only stops future tracking. The old value stays in history, so rotate the key.

Common mistakes

  • Adding .env to .gitignore after it's already tracked. GitHub's docs say tracked files must be untracked first, using git rm --cached.
  • Pointing tests at the production database. A test that creates and deletes records can damage real data.
  • Letting the AI change a test so that it passes. Ask whether the test or the app is wrong before accepting that.
  • Assuming a preview is private. Check your host's protection settings before putting real data on it.

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course