DEV Community

Cover image for 🚀 Why You Should Keep Multiple Backups of Your Code (Don’t Rely Only on GitHub)
Zain Ul Abdeen
Zain Ul Abdeen

Posted on

🚀 Why You Should Keep Multiple Backups of Your Code (Don’t Rely Only on GitHub)

🔒 Don’t Let a GitHub Suspension Kill Your Projects – Keep Multiple Backups of Your Code

Recently, my GitHub account was suspended. My projects, all my repos, and every commit were gone in a second.

That’s when it hit me: as developers, we trust GitHub (or any single platform) way too much. If your account gets suspended, hacked, or if the platform goes down, all your hard work could vanish.

This is a practical guide on how to keep multiple copies of your code in different places—the way professionals do.


🚨 Why Multiple Backups Matter for Devs

  • Suspension risk – Platforms like GitHub, GitLab, and Bitbucket can suspend accounts.
  • Outages happen – Even the biggest platforms can go down.
  • Hacks and data loss – Security breaches or accidental deletions happen.
  • Peace of mind – Having multiple copies means you’ll never lose your code.

Think of it like this:

Code is the heart of your dev journey—don't keep it in just one box.


🔹 1. Push to Multiple Git Remotes

Git makes this easy: you can push to more than one host.

Example: Same Repo, Different Remotes

# Clone your repo
git clone https://github.com/username/myproject.git
cd myproject

# Add GitLab as another remote
git remote add gitlab https://gitlab.com/username/myproject.git
git push --all gitlab

# Add Bitbucket too
git remote add bitbucket https://bitbucket.org/username/myproject.git
git push --all bitbucket
Enter fullscreen mode Exit fullscreen mode

Now your code lives on GitHub + GitLab + Bitbucket. If one fails, the others have your back.


🔹 2. Mirror Clone for Local Backups

A normal clone isn’t enough. Use a mirror clone to grab everything: branches, tags, and refs.

git clone --mirror https://github.com/username/myproject.git
Enter fullscreen mode Exit fullscreen mode

This gives you a perfect local copy. Keep it on your machine or an external drive for an extra layer of protection.


🔹 3. Cloud Storage (Google Drive, Dropbox, OneDrive)

This method isn’t fancy, but it is reliable. Just zip your project and upload it to the cloud.

zip -r myproject-backup.zip myproject/
Enter fullscreen mode Exit fullscreen mode

Upload that .zip to Google Drive, Dropbox, OneDrive, or Mega.

🔑 Pro tip: Automate this process so you don’t forget to do it.


🔹 4. Self-Host Your Git

Want total control? Run your own Git server.

  • Gitea → a lightweight, simple GitHub alternative
  • GitLab CE → a full GitHub-like experience

This is a perfect option if you have a home server, a VPS, or just like being independent.


🔹 5. Automate Backups with a Script

Doing this by hand is painful. It’s better to automate it.

Example: Bash Script (Linux/Mac)

#!/bin/bash
BACKUP_DIR="$HOME/git-backups"
DATE=$(date +%F)

mkdir -p "$BACKUP_DIR/$DATE"

repos=(
  "https://github.com/username/repo1.git"
  "https://github.com/username/repo2.git"
)

for repo in "${repos[@]}"; do
  name=$(basename "$repo" .git)
  git clone --mirror "$repo" "$BACKUP_DIR/$DATE/$name"
done

cd "$BACKUP_DIR"
zip -r "git-backup-$DATE.zip" "$DATE"
Enter fullscreen mode Exit fullscreen mode

Run it with cron (Linux/Mac) or Task Scheduler (Windows).


🔹 6. Automate Backups with PowerShell (Windows)

For Windows devs, here’s a PowerShell script that mirrors your repos and zips them.

# Git Backup Script for Windows
$backupDir = "$HOME\git-backups"
$date = Get-Date -Format "yyyy-MM-dd"
$todayDir = Join-Path $backupDir $date

# Create backup folder
New-Item -ItemType Directory -Force -Path $todayDir | Out-Null

# List of repos
$repos = @(
  "https://github.com/username/repo1.git",
  "https://github.com/username/repo2.git"
)

foreach ($repo in $repos) {
  $name = ($repo.Split("/")[-1]).Replace(".git", "")
  git clone --mirror $repo "$todayDir\$name"
}

# Create a zip archive
$zipFile = "$backupDir\git-backup-$date.zip"
Compress-Archive -Path $todayDir -DestinationPath $zipFile -Force
Enter fullscreen mode Exit fullscreen mode

Save it as backup.ps1 and run it manually, or schedule it with Task Scheduler for daily or weekly backups.


✅ Best Practices for Devs

  • Keep three copies minimum: a local machine copy, one on cloud storage, and one on another Git host.
  • Test restores—backups are useless if you can’t recover them.
  • Use SSH keys for smooth multi-remote pushes.
  • Automate—you should never rely on your memory for backups.

🎯 Final Thoughts

Your code is your craft. Losing it hurts—trust me, I learned the hard way.

Don’t put all your trust in one platform. Distribute, mirror, and back it up.

The next time GitHub, GitLab, or Bitbucket fails, you’ll smile and say:

“No worries, I’ve got backups.”


Over to you:

Where do you keep your backups? Do you trust GitHub 100%, or do you mirror to GitLab or Bitbucket too?

Top comments (3)

Collapse
 
a-k-0047 profile image
ak0047

Thank you for sharing this article.
I found it really helpful and practical.
Since I only use GitHub and don't have any backups elsewhere, I'll definitely try out some of these methods.

Collapse
 
zainulabdeenofficial profile image
Zain Ul Abdeen

ur welcome sure

Collapse
 
syeo66 profile image
Red Ochsenbein (he/him)

What I do is to add multiple pushurls to my origin remote. This way git push automatically pushes to all of them. Also take a look at soft-serve for a really lightweight git server.