Back Up All Your GitHub Repositories

Updated 2026-11-30

GitHub's own redundancy protects GitHub, not you — if your account gets suspended, flagged, or deleted by mistake, their backups don't restore your access. The fix is a one-time script that mirrors every repo you own to a second host, done before anything happens, not after.

Step 1 — list every repository you own

Using the GitHub CLI (gh):

gh repo list <you-or-your-org> --limit 1000 --json nameWithOwner -q '.[].nameWithOwner' > repos.txt

This gives a plain text list, one owner/repo per line, including private repos you have access to.

Step 2 — mirror-clone every repo in one pass

while read repo; do
  git clone --mirror "https://github.com/$repo.git" "backup/$repo.git"
done < repos.txt

--mirror captures every branch and tag, not just the default branch — this is the same format you'd push from to restore the repo elsewhere.

Step 3 — push the mirrors to a second, independent host

A local backup alone is one point of failure away from being useless. Push each mirror to a host you don't depend on GitHub's policies for:

cd "backup/$repo.git"
git remote add rithub "https://rithub.dev/$repo.git"
git push rithub --mirror

Script this across the full repos.txt list and you have a second, working copy of every repository, independent of GitHub's account status.

Step 4 — keep it in sync, not just one-time

A backup taken once goes stale. Re-run the same mirror-clone-and-push loop on a schedule (a weekly cron job, or after any repo you care about gets new commits) so the backup copy is never far behind the original.

What a mirror does and doesn't capture

Frequently asked questions

Does GitHub back up my repos for me?
Only against GitHub's own infrastructure failures — not against account suspension, flags, or accidental deletion on your side.

Fastest way to back up everything?
List repos via gh repo list, loop git clone --mirror over the list.

Where should backups live?
Not only on one disk — push mirrors to a second, independently-run host too.

Sign up freeImport from GitHub