---
title: "Git for vibe coders: never lose a working version again"
description: "Commits, GitHub, rollbacks, branches and .gitignore: the minimum Git you need to vibe code without fear of breaking your app, prompts included."
url: "https://vibe-code.blog/en/git-for-vibe-coders"
lang: "en"
author: "Thierry Gustin"
published: "2026-11-20"
updated: "2026-11-21"
---

# Git for vibe coders: never lose a working version again

> **Key takeaways** — Git takes a snapshot of your project at every commit and lets you return to any of them with one command. For a vibe coder the rule fits in one sentence: commit every version that works, before asking the AI for anything risky. Cursor and Claude Code checkpoints help within a session, but their own documentation recommends Git for lasting history.

Git for vibe coders is insurance: every time your app works, you save a version, and when the AI breaks everything three prompts later, you go back with one command. You do not need to master Git. Six words, five commands and one habit are enough. Here they are, and how to get your agent to run them if you would rather stay out of the terminal.

## Why Git rather than your tool's own history?

Because the history in vibe coding tools is built to undo the last action, not to keep your project safe over time. The vendors say so themselves.

| Tool | What it keeps | What it does not keep | What the docs say |
| --- | --- | --- | --- |
| [Cursor](https://cursor.com/) checkpoints | Files the agent changed during a session | Long-term history; stored separately from Git | "use Git for permanent version control" |
| [Claude Code](https://www.anthropic.com/claude-code) checkpoints | Changes made by Claude's file editing tools, last 100 checkpoints | Files changed only by Bash commands, most subagent edits, your manual edits outside the session | "Not a replacement for version control" |
| Git + GitHub | Every version you commit, with no time limit | Anything you did not commit | — |

In Claude Code, `/rewind` (or pressing Esc twice) opens the rewind menu, and file snapshots are deleted by default about 30 days after the session last saved one. Handy for undoing this afternoon's mistake. Not for finding the version you demoed to a client two months ago.

If you wonder why this matters so much, look at [the 12 mistakes that sink vibe coding projects](https://vibe-code.blog/en/vibe-coding-mistakes): several boil down to "we had a working version and lost it".

## The six Git words you need

These six ideas are all you need to vibe code with peace of mind.

| Word | What it is | Analogy |
| --- | --- | --- |
| Repository | Your project folder, tracked by Git | The binder |
| Commit | A snapshot of all your files at one moment, with a message | A dated, signed page |
| Push | Sending your commits to GitHub | The copy that goes in the safe |
| Branch | A parallel line of work | A draft next to the clean copy |
| Revert | A new commit that undoes an earlier one | A page saying "page 12 is cancelled" |
| .gitignore | The list of files Git must never save | The drawer that never goes in the safe |

[GitHub](https://github.com/) hosts your repositories online. The free plan includes unlimited public and private repositories: make your project private.

## Connecting Lovable to GitHub

If you build on Lovable, GitHub sync gives you Git without typing a command. It works both ways: what you do in Lovable is pushed to GitHub, and what is pushed to GitHub comes back into Lovable.

Three points from the documentation to know before you turn it on:

- Lovable only syncs **one branch at a time**, by default the repository's default branch (usually `main`). A commit pushed to another branch does not show up in Lovable until it is merged or you switch branches in the branch picker.
- Sync **always creates a new repository**: you cannot connect an existing one. Reconnecting after a disconnect also creates a new repository.
- If you delete the repository on GitHub, syncing stops.

The benefit goes beyond backup: your code exists outside [Lovable](https://lovable.dev/). The day you want to continue in Cursor or Claude Code, it is already on GitHub.

## Starting Git on a project with a coding agent

With a coding agent, you can type these commands or ask the agent to run them. For a new project:

```bash
git init
git add .
git commit -m "Starting point: home page and sign-up working"
```

Then, to send the project to GitHub after creating an empty private repository on the site:

```bash
git remote add origin https://github.com/your-account/your-project.git
git push -u origin main
```

Before the first commit, check the `.gitignore` file (see below). It is the step everyone skips and everyone regrets.

## The habit: commit every version that works

The vibe coder's golden rule: commit as soon as something works, and always before a risky prompt.

1. Test the feature the AI just built (the method is in [testing AI-generated code when you are not a developer](https://vibe-code.blog/en/testing-ai-generated-code)).
2. It works: commit with a message that says what works, for example `Booking a slot works`.
3. Ask for the next feature.
4. It breaks and the AI goes in circles: go back to the last commit instead of asking for a fourth fix.

A useful commit message describes the state, not the effort. "Stripe test-mode checkout working" will help you in three weeks. "Fixes" never will.

## Going back to a working version: three situations

The right move depends on what you have already saved.

| Situation | Command | What happens |
| --- | --- | --- |
| The AI broke everything and nothing is committed since the last good version | `git restore .` | Tracked files go back to their saved state. Uncommitted changes are lost |
| The last commit is bad and it is already on GitHub | `git revert HEAD` | Git creates a new commit that undoes the previous one. History is kept |
| You just want to look at or test an old version | `git switch -c test-old <commit-id>` | A branch is created from that version, without touching `main` |

`git log --oneline` lists your commits with their short IDs. Git's documentation is clear on one point: `git reset --hard` throws away all uncommitted changes and is not a substitute for `git revert` when undoing a commit that has been shared. If your agent suggests a `reset --hard`, ask why before saying yes.

> **Do not let the agent rewrite history without you** — Forbid your agent from running `git reset --hard`, `git push --force` or deleting branches without your explicit go-ahead. Those are the three ways to lose a working version for good.

## Branches: experiment without risking the live version

A branch lets you try a big change next to the version that works. If the experiment fails, you drop the branch, and `main` never moved.

```bash
git switch -c dashboard-redesign
# ... work with the AI, commit ...
git switch main
git merge dashboard-redesign
```

On [Vercel](https://vercel.com/), every commit pushed to a branch other than your production branch creates a preview deployment with its own URL by default, so you can test the redesign separately before merging. The article on [deploying to Vercel, Netlify or shared hosting](https://vibe-code.blog/en/deploy-vibe-coded-app) covers this in more detail.

## .gitignore: what must never reach GitHub

The `.gitignore` file lists what Git should ignore. For a vibe-coded app it should contain at least:

```text
.env
.env.local
node_modules/
dist/
.DS_Store
```

The most important line is `.env`, the file that holds your API keys. A key pushed to GitHub, even in a private repository, should be treated as compromised: it is one of the items on the [pre-launch security checklist](https://vibe-code.blog/en/vibe-coding-security).

If the file is already tracked, adding it to `.gitignore` is not enough. GitHub's documentation says you must first stop tracking it with `git rm --cached .env`, then add the rule. And if the key has already reached GitHub: revoke it and create a new one. [Why API keys must never live in your front end](https://vibe-code.blog/en/api-keys-security) explains what is at stake.

## A prompt so your agent handles Git for you

If the terminal puts you off, give your agent these rules once and for all. The best place is its permanent instructions file, as explained in the guide to CLAUDE.md, AGENTS.md and rules files.

```text
Git rules for this project:
- Before any significant change, check everything is committed.
  If not, suggest a commit with a message describing what works.
- After every feature I have approved, suggest a commit.
- Never run git reset --hard, git push --force or delete a branch
  without asking me and explaining what would be lost.
- Never commit a .env file or an API key.
  Check .gitignore before the first commit.
- To undo a commit that has been pushed, use git revert.
```

## And if you really want no terminal at all?

GitHub Desktop is a free, open-source app for Windows and macOS that handles commits, pushes and branches with buttons. You open your project folder, see the list of changed files, write your message and click "Commit". It is a good starting point before you let an agent drive Git.

## Frequently asked questions

## Frequently asked questions

### Do I need to learn Git to vibe code?

You need six ideas: repository, commit, push, branch, revert and .gitignore. You do not have to memorise the commands, because your agent can run them or GitHub Desktop turns them into buttons. What matters is the habit: commit every working version and before every risky request to the AI. That is what lets you go back without losing anything.

### Do Cursor or Claude Code checkpoints replace Git?

No, and their documentation says so. Cursor checkpoints are stored locally, separately from Git, and are meant for undoing agent changes. Claude Code checkpoints do not track files changed only by Bash commands and are deleted by default about 30 days after the session. Use them to undo quickly, and Git to keep your history.

### How do I go back to a previous version with Git?

If nothing is committed since the last good version, `git restore .` puts tracked files back to their last saved state. If the bad commit is already on GitHub, `git revert HEAD` creates a commit that undoes it while keeping history. To simply explore an old version, create a branch from its commit ID with `git switch -c`.

### Does Lovable back up my code to GitHub?

Yes, if you turn on GitHub sync. It works both ways but only follows one branch at a time, by default the main branch. It always creates a new repository, so you cannot connect an existing one. The upside is that your code lives outside Lovable and you can pick it up in another tool.

### I pushed my API key to GitHub. What now?

Revoke the key immediately in the service that issued it and create a new one: deleting the file is not enough, because it stays in Git history. Then stop tracking the file with `git rm --cached .env`, add `.env` to `.gitignore` and commit. Finally, check your bill and usage logs for anything unusual.

## Sources

- [Checkpoints — Cursor Docs](https://cursor.com/docs/agent/chat/checkpoints)
- [Checkpointing — Claude Code Docs](https://code.claude.com/docs/en/checkpointing)
- [GitHub integration — Lovable Documentation](https://docs.lovable.dev/integrations/github)
- [git-revert — Git Documentation](https://git-scm.com/docs/git-revert)
- [git-restore — Git Documentation](https://git-scm.com/docs/git-restore)
- [git-switch — Git Documentation](https://git-scm.com/docs/git-switch)
- [Ignoring files — GitHub Docs](https://docs.github.com/en/get-started/git-basics/ignoring-files)
- [About GitHub Desktop — GitHub Docs](https://docs.github.com/en/desktop/overview/about-github-desktop)
- [Pricing — GitHub](https://github.com/pricing)
- [Environments — Vercel Docs](https://vercel.com/docs/deployments/environments)

— Thierry Gustin, Formateur en intelligence artificielle (GustinAI) · November 21, 2026
