Back up your Replit projects using three methods: push to GitHub through the built-in Git tool for full version control, download your project as a ZIP file for local backups, and use Replit's File History to browse and restore previous versions of individual files. For automated backups, set up a scheduled script that commits and pushes to GitHub on a regular interval. Always back up before major Agent changes, since Agent can sometimes delete or overwrite code unexpectedly.
Back Up Your Replit Projects with Git, ZIP, and File History
Losing your code on Replit is more common than you might expect. Agent can delete files while attempting fixes, the filesystem resets on deployment, and workspace issues can cause data loss. This tutorial covers every backup method available in Replit: pushing to GitHub for remote version control, downloading ZIP archives for local copies, using built-in File History for quick restores, and setting up automated backup scripts. You will learn how to protect your work with minimal effort.
Prerequisites
- A Replit account (any plan)
- An existing Repl with code you want to back up
- A GitHub account (free tier works) for Git-based backups
- Basic understanding of what Git does (tracks file changes over time)
Step-by-step guide
Connect your Repl to GitHub
Connect your Repl to GitHub
Open the Git tool from the left sidebar Tools dock. If your project is not yet a Git repository, click Initialize Repository. Then click Connect to GitHub and authorize Replit to access your GitHub account. Choose an existing repository or create a new one. Replit syncs your project files to the main branch. This gives you a complete remote backup of your code on GitHub that persists even if something happens to your Replit workspace.
Expected result: Your Repl is linked to a GitHub repository and shows the connection status in the Git tool.
Commit and push changes with the Git tool
Commit and push changes with the Git tool
After making changes to your code, open the Git tool. You will see a list of modified files. Stage the files you want to back up by clicking the plus icon next to each file, or click Stage All to include everything. Write a descriptive commit message and click Commit. Then click Push to send your changes to GitHub. Replit can auto-generate commit messages using AI if you click the sparkle icon next to the message field.
Expected result: Your changes appear in the GitHub repository under the main branch.
Push from the Shell for more control
Push from the Shell for more control
For more granular Git control, use the Shell. You can stage specific files, create branches, view diffs, and push to any remote. The Shell provides the full Git CLI including commands like git log, git diff, git branch, and git stash. For private repositories, store a GitHub personal access token in Secrets under the key GIT_URL and use it for authentication when pushing.
1# Check status of changed files2git status34# Stage specific files5git add src/index.ts src/utils.ts67# Commit with a message8git commit -m "Add user authentication feature"910# Push to GitHub11git push origin main1213# For private repos, use a personal access token:14# Store in Secrets: GIT_URL = https://TOKEN@github.com/user/repo.git15# Then push: git push $GIT_URL mainExpected result: Your commits appear in the GitHub repository with full history.
Download your project as a ZIP file
Download your project as a ZIP file
For a quick local backup, click the three-dot menu at the top of the file tree panel and select Download as ZIP. This downloads your entire project directory including all files, folders, and configuration. Store the ZIP on your local machine, cloud storage, or an external drive. This method does not require GitHub and works on all plans including the free Starter tier.
Expected result: A ZIP file downloads to your computer containing your full project.
Use File History to restore individual files
Use File History to restore individual files
Replit tracks changes to individual files automatically. Open File History from the Tools dock in the left sidebar. Select a file to see its version history with timestamps and diffs. Click on any previous version to see what the file looked like at that point. Click Restore to revert the file to that version. This is especially useful when Agent modifies a file unexpectedly and you need to undo just that one change without reverting the entire project.
Expected result: You can browse previous versions of any file and restore them with one click.
Set up an automated backup script
Set up an automated backup script
Create a script that automatically commits and pushes to GitHub on a schedule. Write a simple shell script that stages all changes, commits with a timestamp, and pushes to the remote. Then use a Scheduled Deployment to run this script at regular intervals, such as every day at midnight. This ensures you always have a recent backup even if you forget to push manually.
1#!/bin/bash2# backup.sh — Automated backup script3# Run this on a schedule via Replit Scheduled Deployment45cd /home/runner/$REPL_SLUG67# Configure Git identity8git config user.email "backup@replit.dev"9git config user.name "Automated Backup"1011# Stage all changes12git add -A1314# Commit with timestamp (skip if nothing changed)15git diff --cached --quiet || git commit -m "Automated backup: $(date '+%Y-%m-%d %H:%M:%S')"1617# Push to GitHub18git push origin main1920echo "Backup completed at $(date)"Expected result: The script runs on schedule and pushes any new changes to GitHub automatically.
Complete working example
1#!/bin/bash2# backup.sh — Complete automated backup script for Replit3# Pushes all changes to GitHub on a schedule4# Set up as a Scheduled Deployment to run daily56set -e78# Navigate to project root9cd /home/runner/$REPL_SLUG1011# Configure Git identity (required for commits)12git config user.email "backup@replit.dev"13git config user.name "Automated Backup"1415# Check if remote is configured16if ! git remote get-url origin > /dev/null 2>&1; then17 echo "ERROR: No Git remote configured."18 echo "Run: git remote add origin https://github.com/user/repo.git"19 exit 120fi2122# Pull latest changes first to avoid conflicts23git pull origin main --rebase || echo "Pull failed, continuing with push"2425# Stage all changes including new files26git add -A2728# Check if there are changes to commit29if git diff --cached --quiet; then30 echo "No changes to back up at $(date)"31 exit 032fi3334# Commit with descriptive timestamp35git commit -m "Automated backup: $(date '+%Y-%m-%d %H:%M:%S UTC')"3637# Push to GitHub38# For private repos, use $GIT_URL stored in Secrets39if [ -n "$GIT_URL" ]; then40 git push "$GIT_URL" main41else42 git push origin main43fi4445echo "Backup completed successfully at $(date)"46echo "Files backed up: $(git diff --name-only HEAD~1)"Common mistakes when backking up Replit projects
Why it's a problem: Relying only on the Replit workspace without any external backup, then losing code when Agent deletes files
How to avoid: Push to GitHub regularly. Git gives you full version history so you can revert any change Agent makes.
Why it's a problem: Getting the error Git Error UNAUTHENTICATED Failed to authenticate with the remote when pushing
How to avoid: Reauthorize GitHub at replit.com/integrations. If that fails, generate a GitHub personal access token, store it in Secrets as GIT_URL, and push with git push $GIT_URL main from the Shell.
Why it's a problem: Assuming downloaded ZIP files include Git history
How to avoid: ZIP downloads only contain the current state of your files. They do not include Git commit history. Use Git push for version-controlled backups with full history.
Why it's a problem: Not backing up deployment secrets alongside code
How to avoid: Document your environment variable names and their purposes in a .env.example file (without actual values). Store actual secret values in a secure password manager outside of Replit.
Best practices
- Commit and push to GitHub before asking Agent to make significant changes to your project
- Download a ZIP backup before major refactoring sessions as an insurance policy
- Use descriptive commit messages so you can find specific versions later in your Git history
- Set up automated daily backups using a Scheduled Deployment to ensure you never lose more than a day of work
- Store your GitHub personal access token in Secrets, never hardcode it in scripts or code
- Use Git branches for experimental features so you can discard them without affecting your main backup
- Check File History immediately after Agent makes unexpected changes to restore individual files quickly
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I want to set up automated backups for my Replit project to GitHub. Give me a bash script that commits and pushes all changes with a timestamp, handles authentication with a personal access token stored in environment variables, and skips the commit if nothing has changed. Also explain how to run this on a schedule using Replit Scheduled Deployments.
Set up automated daily backups for my project. Create a backup.sh script that commits all changes with a timestamp and pushes to my GitHub repository. Configure the .replit file to run this script. Use my GitHub token stored in Secrets under the key GIT_URL for authentication.
Frequently asked questions
Replit maintains File History for individual files, which lets you restore previous versions. However, there is no automatic remote backup. You must push to GitHub or download ZIP files yourself to have an off-platform backup.
The deployment filesystem resets on every publish. Only files in your source code directory survive. Any files created at runtime (uploads, logs, temp files) are deleted. This does not affect your workspace files, only the deployed container.
File History works on individual files, not the entire project. For full project restoration, use Git history from your GitHub repository. This is why pushing to GitHub regularly is critical.
Go to replit.com/integrations and reauthorize your GitHub connection. If that does not work, create a personal access token on GitHub, store it in Replit Secrets as GIT_URL with the format https://TOKEN@github.com/user/repo.git, and push using git push $GIT_URL main.
Scheduled Deployments require a paid plan. On the free tier, you can run the backup script manually from the Shell or set up a free external service like GitHub Actions to trigger the backup via a webhook.
Yes. Secrets are not included in Git or ZIP downloads. Create a .env.example file listing all required variable names without values, and store actual secret values in a password manager. For teams managing production Replit apps, RapidDev can help establish secure secret management workflows.
Use a three-layer approach: push to GitHub daily for version-controlled backups, download a ZIP before major changes as a snapshot, and rely on File History for quick file-level restores. Automated daily pushes via a Scheduled Deployment provide the best hands-off protection.
Agent creates checkpoints as it works but does not modify your Git history. You can revert to Agent checkpoints independently of Git. Having both gives you two layers of undo capability.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation