Git is Lovable's built-in version control foundation. Every Lovable project automatically syncs bi-directionally with a GitHub repository — every AI-generated change is committed in real time, and you can push external changes back to Lovable. No setup required. This guide explains Git concepts like commits, branches, and pull requests in plain English, and covers how to connect GitHub, manage history, and recover from mistakes.
Git in Lovable: Your Code's Safety Net
Every time you send a message in Lovable's chat and the AI generates code, that change is automatically committed to Git. Think of a commit like a named save point in a video game — you can always go back to any previous save point if something breaks. Lovable stores all of these commits in a GitHub repository linked to your project, giving you a complete, browsable history of every change the AI has ever made to your app.
For non-technical founders, the most important Git concept to understand is not the technical plumbing — it is the undo button it provides. Lovable's version history panel (accessible via the clock icon in the editor) lets you browse every AI-generated change and restore any earlier version with one click, no terminal commands needed. This is Git working behind the scenes.
When you connect your Lovable project to GitHub (via Settings → Connectors → GitHub), you unlock collaboration features: teammates can view the code in GitHub's web interface, create branches for experimental changes, and submit pull requests for review before merging. Lovable's sync is bi-directional — changes you or your team make directly in GitHub appear in Lovable automatically. The only hard rule: never rename, move, or delete the linked GitHub repository after connecting, as this permanently breaks the sync and requires reconnecting from scratch.
Integration method
Git is a core platform feature of Lovable rather than a third-party integration — every project is backed by a GitHub repository with automatic bi-directional sync. Edge Functions are not required for Git itself, but you can use them to interact with the GitHub REST API programmatically: for example, to fetch commit history, trigger status checks, or post build metadata. This guide covers both the native Git workflow built into Lovable and how to extend it via the GitHub API if needed.
Prerequisites
- A Lovable project (free or paid — all plans include Git history)
- A GitHub account (free) if you want to connect to GitHub for external visibility
- No Git knowledge required for basic version history — the Lovable UI handles everything
- A GitHub Personal Access Token or GitHub OAuth connection for Edge Function API calls (only needed for the advanced commit-display use case)
- Familiarity with Lovable's editor panels (chat, preview, Cloud tab)
Step-by-step guide
Understand what Git does in Lovable and why it matters
Understand what Git does in Lovable and why it matters
Before touching any settings, it helps to understand what Git is doing behind the scenes every time you use Lovable. Git is a version control system — a tool that records every change made to your code over time, who made it, and when. In Lovable, every message you send in the AI chat that generates code creates a Git commit automatically. You do not need to click 'Save' or type any commands. Here is a quick glossary of Git terms you will encounter in Lovable's UI: Commit: A saved snapshot of your code at a specific moment. Lovable creates one for every AI-generated change. Branch: A separate timeline of commits. By default, everything goes into the 'main' branch. Branches let you try risky changes without affecting the main version of your app. Merge: Combining changes from one branch back into another (e.g., merging an experimental branch back into main). Pull Request (PR): A formal request to merge one branch into another, usually including a code review. Common in team workflows. Push: Uploading your local commits to a remote server (GitHub). Lovable does this automatically. Pull: Downloading commits from a remote server into your local copy. Lovable also handles this automatically. The practical takeaway for non-technical founders: you already have a full Git history of your app just by using Lovable. The GitHub connection makes that history visible outside of Lovable.
Pro tip: The clock/history icon in Lovable's left panel opens your version history. Think of it as your undo history for the entire project — every AI change is listed there with a timestamp.
Expected result: You understand that Lovable automatically creates Git commits for every AI change, and you know what commits, branches, and pull requests mean in practical terms.
Connect your Lovable project to GitHub
Connect your Lovable project to GitHub
Connecting to GitHub is a two-step process: first you authorize Lovable to access your GitHub account via OAuth, then you link your specific project to a repository. Lovable creates a new repository for your project — you cannot import an existing GitHub repository into Lovable (only export from Lovable to GitHub). To connect: open your Lovable project and click the GitHub icon in the top-right corner of the editor. If this is your first time, you will be prompted to connect your GitHub account — click 'Connect GitHub' and follow the OAuth authorization flow in the popup window. Grant Lovable access to either all repositories or specific ones depending on your preference. Once your GitHub account is connected, click the GitHub icon again and select 'Connect project'. Choose the organization or personal account where you want the repository created, give the repository a name, and click 'Transfer anyway' to confirm. Lovable will create the repository, push your current code, and establish the bi-directional sync. From this point on, every AI-generated change in Lovable automatically commits and pushes to the main branch of that GitHub repository. If you or a teammate make a change directly in GitHub (e.g., edit a file via the GitHub web interface), that change will sync back to Lovable within a few minutes. Critical warning: do not rename, move, or delete the GitHub repository after connecting. Doing so permanently breaks the sync link, and reconnecting requires contacting Lovable support or starting a new connection from scratch.
Help me connect my Lovable project to GitHub. I want to create a new private GitHub repository called 'my-app' in my personal GitHub account and sync all my Lovable code to it. Walk me through using Settings → Connectors → GitHub.
Paste this in Lovable chat
Pro tip: Choose a repository name you will be happy with long-term. While you can rename GitHub repositories, doing so after connecting to Lovable will break the sync. If you must rename later, disconnect and reconnect the integration.
Expected result: Your Lovable project is connected to a GitHub repository. The GitHub icon in the top-right shows a green connected state. You can open the repository in GitHub and see your current code plus commit history.
Use version history to roll back a broken change
Use version history to roll back a broken change
Lovable's version history is the most immediately useful Git feature for non-technical founders. Every time the AI makes a code change, Lovable creates a snapshot. If a new change breaks your app — or the AI goes in a direction you do not want — you can restore any previous snapshot in a single click. To access version history: click the clock icon in the left sidebar of the Lovable editor. A panel opens showing a chronological list of all AI-generated changes, each labeled with a timestamp and a brief description of what changed. Scroll through the list to find the version you want to return to — the one just before things went wrong. Click on any entry in the list to preview that version in the right panel. You can see exactly what the app looked like at that point. If it is the state you want to restore, click the 'Restore this version' button. Lovable will reset your project code to that snapshot and create a new commit recording the rollback. Important: restoring a version does not delete the commits that came after it — they are still in your Git history. This means you can always go back forward again if you change your mind. Think of it like multiple save slots in a video game: restoring an old save does not erase the newer saves. If your project is connected to GitHub, the restored version will be pushed to GitHub as well, so the GitHub repository reflects the rolled-back state.
Something broke in my app after the last few AI changes. I want to go back to how it looked before. Help me use the version history in Lovable to find the last version where my app was working correctly and restore it.
Paste this in Lovable chat
Pro tip: Before restoring a version, take note of the current state — write down what the AI was working on. After restoring, you can ask the AI to redo the work more carefully, using the old approach as a reference.
Expected result: Your app is restored to a previous working state. A new commit appears in Lovable's version history and in GitHub (if connected) recording the rollback. The AI chat history is preserved, so you can ask the AI to try a different approach.
Use the GitHub API via Edge Function for advanced Git data
Use the GitHub API via Edge Function for advanced Git data
If you want to programmatically display Git data inside your Lovable app — for example, showing recent commits in a changelog, displaying the current deployed version, or building a deployment status widget — you need to call the GitHub REST API from a server-side Edge Function. Direct frontend calls to the GitHub API using a personal access token would expose the token in the browser, which is a security risk. Create an Edge Function called github-commits that accepts a repository path (owner/repo) as a query parameter, reads your GITHUB_TOKEN from Secrets, and proxies the GitHub API's commits endpoint. Store your GitHub Personal Access Token in Lovable's Cloud tab → Secrets panel under the name GITHUB_TOKEN. Generate a token at github.com → Settings → Developer settings → Personal access tokens — a classic token with the 'repo' scope (or a fine-grained token with 'Contents: Read' permission) is sufficient for read-only commit access. The GitHub REST API endpoint for listing commits is: GET https://api.github.com/repos/{owner}/{repo}/commits?per_page=10. The API returns an array of commit objects, each with sha (the full 40-character commit hash), commit.message, commit.author.name, commit.author.date, and html_url (a link to view the commit on GitHub). Once the Edge Function is deployed, build a React component that calls it and renders a commit timeline or changelog widget. This pattern is useful for SaaS apps that want to show a public-facing changelog driven by Git commit messages.
Create a Supabase Edge Function called 'github-commits' that fetches recent commits from a GitHub repository. Read GITHUB_TOKEN from Deno.env.get(). Accept 'owner' and 'repo' query parameters. Call https://api.github.com/repos/{owner}/{repo}/commits?per_page=10 with Authorization: Bearer ${GITHUB_TOKEN} and User-Agent: Lovable-App headers. Return the array of commits with sha (first 7 chars), message (first line only), author name, and date. Include CORS headers.
Paste this in Lovable chat
1import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'23const corsHeaders = {4 'Access-Control-Allow-Origin': '*',5 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',6}78serve(async (req) => {9 if (req.method === 'OPTIONS') {10 return new Response('ok', { headers: corsHeaders })11 }1213 try {14 const githubToken = Deno.env.get('GITHUB_TOKEN')15 if (!githubToken) {16 return new Response(17 JSON.stringify({ error: 'GITHUB_TOKEN not found in Secrets' }),18 { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }19 )20 }2122 const url = new URL(req.url)23 const owner = url.searchParams.get('owner')24 const repo = url.searchParams.get('repo')2526 if (!owner || !repo) {27 return new Response(28 JSON.stringify({ error: 'Missing owner or repo query parameters' }),29 { status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }30 )31 }3233 const apiUrl = `https://api.github.com/repos/${owner}/${repo}/commits?per_page=10`34 const response = await fetch(apiUrl, {35 headers: {36 'Authorization': `Bearer ${githubToken}`,37 'Accept': 'application/vnd.github.v3+json',38 'User-Agent': 'Lovable-App',39 },40 })4142 if (!response.ok) {43 const errorText = await response.text()44 return new Response(45 JSON.stringify({ error: `GitHub API error: ${response.status}`, details: errorText }),46 { status: response.status, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }47 )48 }4950 const commits = await response.json()5152 const simplified = commits.map((c: any) => ({53 sha: c.sha.substring(0, 7),54 message: c.commit.message.split('\n')[0],55 author: c.commit.author.name,56 date: c.commit.author.date,57 url: c.html_url,58 }))5960 return new Response(61 JSON.stringify(simplified),62 { headers: { ...corsHeaders, 'Content-Type': 'application/json' } }63 )64 } catch (error) {65 return new Response(66 JSON.stringify({ error: error.message }),67 { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }68 )69 }70})Pro tip: The User-Agent header is required by the GitHub API. Requests without it return a 403 error. Always include it in Edge Functions calling GitHub.
Expected result: The Edge Function is deployed and returns simplified commit data from your GitHub repository. A React component displays the last 10 commits as a changelog or timeline widget in your Lovable app.
Understand branching and when to use it in Lovable
Understand branching and when to use it in Lovable
Branches are separate timelines of development. Lovable's default behavior puts everything in the main branch — every AI change goes there directly. For solo founders building quickly, this is usually fine. But when you are working with a developer or making risky experimental changes, branches become valuable. Currently (March 2026), Lovable's branch switching feature is available in Settings → Account → Labs as an experimental feature. When enabled, you can create a new branch for a specific feature or experiment, work in that branch without affecting the main app, and then merge it back when you are satisfied. This is particularly useful for A/B testing new features or letting a developer review AI-generated code before it goes live. To work with branches outside of Lovable's UI, you can use the GitHub web interface. Navigate to your connected GitHub repository, click the branch dropdown (it shows 'main' by default), type a new branch name, and click 'Create branch'. Any changes made on that branch in GitHub will sync to Lovable if you have the experimental branch feature enabled. A practical pattern for non-technical founders: use Lovable's main branch for stable, working code that users see. When trying a major new feature, ask the AI to work in a new branch. If the feature works, merge it. If not, delete the branch — your main app is untouched. For complex Git workflows involving multiple branches, code reviews, and CI/CD pipelines, RapidDev's team can help set up a professional Git workflow tailored to your team's needs.
Enable branch support in Lovable's Labs settings. Create a new branch called 'feature/user-profile' for me to experiment with adding a user profile page. I want to keep my main branch stable while I try this new feature.
Paste this in Lovable chat
Pro tip: If Lovable's branch feature is not yet out of Labs for your account, use GitHub's web interface to create and manage branches manually. Changes on non-main branches will not auto-sync to Lovable until the branch feature is fully released.
Expected result: A new branch exists in your GitHub repository. Changes made on that branch are isolated from the main branch. You can switch between branches in Lovable (if the Labs feature is enabled) to see the different versions of your app.
Common use cases
Connect your Lovable project to GitHub for code backup and collaboration
By default, Lovable commits your code to an internal Git repository. Connecting to a GitHub repository makes that history visible in your GitHub account, shareable with teammates, and accessible for external deployment pipelines like Vercel or Netlify. It takes about two minutes to set up.
Connect my Lovable project to GitHub. I want all my code backed up to a GitHub repository so I can share it with my developer and deploy it to Vercel. Walk me through the steps to connect Settings → Connectors → GitHub.
Copy this prompt to try it in Lovable
Display recent Git commit history from GitHub in your app
If you are building a developer-facing tool or an internal ops dashboard, surfacing recent GitHub commit activity can be valuable. An Edge Function proxies the GitHub REST API to fetch commit history without exposing your GitHub token to the browser.
Create a Supabase Edge Function called 'github-commits' that fetches the last 10 commits from my GitHub repository using the GitHub REST API. Store my GITHUB_TOKEN in Secrets. Accept a 'repo' query parameter in the format owner/repo. Return each commit's sha (first 7 chars), message, author name, and date. Then build a React component that displays this as a timeline.
Copy this prompt to try it in Lovable
Recover a previous version after an AI change breaks your app
If a recent AI-generated change introduces a bug you cannot easily fix, Lovable's version history lets you restore a previous working state in seconds. This is the most practical Git feature for non-technical founders and requires zero Git knowledge.
My app stopped working after the last few AI changes. I need to roll back to the version from two hours ago. How do I use Lovable's version history to restore a previous working state without losing my GitHub connection?
Copy this prompt to try it in Lovable
Troubleshooting
GitHub sync is broken — Lovable changes are not appearing in GitHub
Cause: The most common cause is that the GitHub repository was renamed, moved to a different organization, or deleted after Lovable connected to it. Lovable stores a pointer to the original repository path, and any change to that path breaks the sync permanently.
Solution: Do not rename the repository. If it has already been renamed, go to Lovable Settings → Connectors → GitHub, disconnect the current connection, and reconnect using the repository's new name. Note: you may lose some sync history during this process. Contact Lovable support if the issue persists.
Edge Function returns 403 from GitHub API — 'Must have push access to repository'
Cause: The GitHub Personal Access Token used in GITHUB_TOKEN either lacks the necessary repository scope or was generated for a different account that does not have access to the repository you are querying.
Solution: Generate a new GitHub token at github.com → Settings → Developer settings → Personal access tokens → Fine-grained tokens. Grant it 'Contents: Read' access for the specific repository. Update the GITHUB_TOKEN secret in Lovable Cloud tab → Secrets panel with the new token value.
GitHub API returns 403 with 'Missing User-Agent'
Cause: The GitHub API requires every request to include a User-Agent header. Edge Functions that call the GitHub API without this header receive a 403 error, which looks like an authentication error but is actually a missing header error.
Solution: Add the 'User-Agent' header to your fetch() call in the Edge Function. Set it to any descriptive string — for example, 'User-Agent': 'Lovable-App'. The code template above includes this header.
1const response = await fetch(apiUrl, {2 headers: {3 'Authorization': `Bearer ${githubToken}`,4 'Accept': 'application/vnd.github.v3+json',5 'User-Agent': 'Lovable-App',6 },7})Version history restore does not appear in the GitHub repository
Cause: If Lovable's GitHub sync is connected, version restores should push automatically. If the push is missing, the sync may be temporarily delayed or the connection may have a transient error.
Solution: Wait 2-3 minutes and refresh your GitHub repository page. If the commit still does not appear, check Lovable's GitHub connection status by clicking the GitHub icon in the top-right. If the connection shows as disconnected, reconnect it. You can also manually trigger a sync by making a minor AI change (e.g., ask the AI to add a comment) which forces a new commit and push.
Best practices
- Never rename, move, or delete your connected GitHub repository — this is the single most common cause of permanent sync breakage in Lovable.
- Use Lovable's version history (clock icon in sidebar) as your primary undo mechanism rather than trying to reverse AI changes manually — it is faster and more reliable.
- Connect to GitHub early in your project, not after the app is complete — having a full Git history from the beginning makes debugging much easier.
- Use descriptive AI prompts so that commit messages are meaningful — Lovable uses your prompt text as the commit message, so 'Add stripe payment button to checkout page' produces a much more useful history entry than 'update stuff'.
- Keep your GitHub repository private until you are ready to share, especially if your app handles user data or you plan to add API keys as environment variables.
- Review auto-generated code in GitHub's web interface before deploying to production — clicking through files in GitHub often reveals issues that are not obvious in Lovable's preview.
- For team projects, establish a branching convention early: main = stable/live, feature/* = in-progress work. This prevents accidental overwrites of working code.
- Store all API tokens for the GitHub Edge Function integration in Lovable's Cloud Secrets — never embed them in code that ends up in your Git history.
Alternatives
GitLab is available as a native Lovable shared connector and is a good alternative if your team already uses GitLab for project management alongside version control.
VS Code with Git integration lets you clone your Lovable GitHub repository and make changes locally with full IDE tooling, useful for developers who prefer working outside the browser.
Docker pairs well with Git for containerizing your Lovable-generated app, making it easy to deploy consistently across environments using the GitHub-synced repository as the source.
Frequently asked questions
Do I need to know Git to use Lovable?
No. Lovable handles all Git operations automatically — every AI change is committed and pushed without any action from you. The version history UI gives you rollback capability with a single click. Git knowledge only becomes useful if you want to collaborate with developers via GitHub pull requests or set up external deployment pipelines.
What happens to my Git history if I delete my Lovable project?
If you have connected your project to GitHub, the repository and its full commit history remain in your GitHub account even after deleting the Lovable project. Your code is not lost. If you did not connect to GitHub, the internal Git history is deleted with the project — another reason to connect to GitHub early.
Can multiple people work on the same Lovable project via Git?
Yes, through GitHub. Each collaborator can clone the repository, make changes, push to a branch, and create a pull request. Lovable will sync changes merged into the main branch back into the project. However, direct Lovable AI editing is one-user-at-a-time — simultaneous AI sessions on the same project are not supported.
Is my code safe in Lovable's Git history?
Lovable's internal Git storage is managed by the platform and backed up. For maximum safety, connect your project to GitHub so you have an independent copy of your entire commit history outside Lovable. This protects you even in the unlikely event of a Lovable platform issue.
Why does my GitHub repository show hundreds of small commits from Lovable?
Lovable creates a commit for every AI-generated change, which can accumulate quickly during active development. This is normal and expected. If you want a cleaner Git history for a specific branch, you can use GitHub's 'Squash and merge' option when merging a branch, which combines all commits into one. This is purely cosmetic and does not affect your app's functionality.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation