読み物Git · DevOps

Level: Pro

Git Migration, Mirroring, Backup, and Avoiding Vendor Lock-In

Move repositories between platforms with full history, keep live mirrors, make backups you've actually restored, and keep the cost of leaving any platform low.

Edeeson Opina9 min read

A Pro lesson card: lesson 15 of the Git & Version Control series, Git Migration, Mirroring, Backup, and Avoiding Vendor Lock-In, with the Miso fox cheering.

What you’ll learn

  • Migrate full Git history with mirror clones and pushes
  • Plan what platform data to import, recreate, or archive
  • Set up push and pull mirrors with one source of truth
  • Back up Git data, LFS objects, and platform data, and test restores
  • Keep exit costs low by design
On this page
  1. Before you start
  2. What moves with Git, and what doesn't
  3. Moving the Git history
  4. Moving platform data
  5. A migration checklist
  6. Mirroring: a live second copy
  7. Backups you can trust
  8. An automated backup script
  9. Avoiding vendor lock-in
  10. Common mistakes and troubleshooting
  11. Practical exercise: migrate, mirror, and restore
  12. Key takeaways
  13. References
  14. What's next

Platforms change their prices, terms, and features; companies merge; services go down; accounts get locked. Because Git is distributed, your history is never truly trapped on one platform, but everything around it (issues, reviews, CI configuration, permissions, releases) can be. This final lesson shows how to move a repository between platforms with its full history, keep live mirrors on a second platform, make backups you've actually tested, and design your setup so that leaving a platform is a project measured in hours, not months.

Before you start

You should be comfortable with remotes, tags, and history from the earlier lessons, LFS from Managing Large Codebases: Monorepos, Git LFS, Submodules, and Worktrees, and CI portability from lesson 11. Practice migrations between test repositories first.

What moves with Git, and what doesn't

Git data moves perfectly with standard commands: every commit, branch, tag, and their history, identical down to the commit IDs.

Platform data doesn't move with git push:

  • issues, comments, labels, and milestones;
  • pull or merge requests and their review discussions;
  • wikis (often a separate Git repository, which helps);
  • releases and their attached files, package registries, and LFS objects;
  • CI/CD configuration, runners, secrets, and environments;
  • permissions, teams, branch protection, webhooks, and integrations.

Planning a migration means deciding, for each of these, whether to move it with an import tool, recreate it, or archive it.

Moving the Git history

A normal clone only creates local branches for the default branch. To copy everything (all branches, tags, and other refs), use a mirror clone and a mirror push:

Shell
$ git clone --mirror git@old.your-company.test:team/app.git app.git
Cloning into bare repository 'app.git'...
done.

$ cd app.git
$ git push --mirror git@new.your-company.test:team/app.git
To new.your-company.test:team/app.git
 * [new branch]      feature/x -> feature/x
 * [new branch]      main -> main
 * [new tag]         v1.0.0 -> v1.0.0

Create the destination repository empty first (no README or license), or the push will conflict. Then verify that the refs match:

Shell
git ls-remote git@old.your-company.test:team/app.git | sort > old.txt
git ls-remote git@new.your-company.test:team/app.git | sort > new.txt
diff old.txt new.txt

Some platforms add their own read-only refs, such as GitHub's refs/pull/*, which the destination will reject; those errors are expected and harmless.

Because a mirror push copies objects unchanged, every commit keeps its ID, and signed commits and tags still verify on the new platform. If the IDs differ, something rewrote history along the way (for example a conversion tool), and links to old commits in issues, documentation, or release notes will break.

If the repository uses Git LFS, the mirror push doesn't copy LFS content. Fetch and push it separately:

Shell
git lfs fetch --all origin
git lfs push --all git@new.your-company.test:team/app.git

Moving platform data

Most platforms offer importers that move more than Git data:

  • Forgejo and Gitea can migrate repositories from GitHub, GitLab, Gitea, and others, optionally including issues, labels, milestones, pull requests, releases, and wiki, using an access token for the source.
  • GitLab has importers for GitHub, Bitbucket, Gitea, and others, and can export and import GitLab projects between instances.
  • GitHub offers an importer for repositories from other hosts and tools for larger enterprise migrations.

Importers vary in what they carry over and how they map users, so do a trial run on a test project and check comments, labels, and links before migrating for real. Things that importers rarely handle completely: CI secrets (re-enter them), webhooks and integrations, branch protection, and user mappings for people without accounts on the new platform.

A migration checklist

  1. Inventory: repositories, LFS usage, wikis, releases, CI workflows, secrets, webhooks, integrations, and who has access.
  2. Trial migration of one representative repository, including issues and pull requests if you need them.
  3. Port CI (lesson 11): with build logic in scripts, only the thin configuration changes.
  4. Recreate secrets, branch protection, teams, and webhooks.
  5. Freeze changes on the old platform briefly, run the final migration, verify refs and LFS objects.
  6. Update remotes for everyone (git remote set-url origin <new-url>), and links in documentation, package metadata, and badges.
  7. Archive the old repository read-only, with a notice pointing to the new home. Keep it until you're sure nothing was missed.

Mirroring: a live second copy

A mirror keeps a second repository updated automatically. Uses include a public read-only copy on another platform, a backup on independent infrastructure, or a gradual migration.

Platform mirroring features:

  • GitLab push mirrors send changes from a GitLab project to another repository; they're available in all tiers. Pull mirrors, which copy from another location into GitLab, need a paid tier.
  • Forgejo and Gitea support both pull mirrors (copy from elsewhere on a schedule) and push mirrors.
  • Any platform can be mirrored with a scheduled CI job or a cron job that runs git fetch and git push --mirror.

You can also push to two platforms from your own machine by adding a second push URL to a remote:

Shell
git remote set-url --add --push origin git@primary.your-company.test:team/app.git
git remote set-url --add --push origin git@backup.your-company.test:team/app.git
git push origin main      # goes to both

Treat one platform as the source of truth for changes. If people push to both independently, the mirrors diverge, and a mirror push from one side would delete the other's work.

Backups you can trust

Every clone is a copy of the history, but a copy isn't a backup strategy. A good backup is independent of the platform, complete, regular, and tested.

A bundle packs a whole repository, all refs and history, into one file that's easy to store anywhere:

Shell
$ git clone --mirror git@code.your-company.test:team/app.git app.git
$ cd app.git
$ git bundle create ../app-2026-11-01.bundle --all
$ git bundle verify ../app-2026-11-01.bundle
The bundle records a complete history.
The bundle uses this hash algorithm: sha1

Restoring is just cloning from the file:

Shell
$ git clone app-2026-11-01.bundle restored
$ git -C restored log --oneline --all
f1eea03 a
3e8f0b4 b

A sensible backup plan:

  • Follow the 3-2-1 rule: three copies, on two kinds of storage, one off-site or on a different provider.
  • Back up everything the repository needs: Git data (mirror clone or bundle), LFS objects, wikis, and platform data such as issues and releases, exported through the platform's API or export feature.
  • Automate it on a schedule, and alert when a backup fails.
  • Encrypt backups of private code, and keep the keys separate from the backups.
  • Test restores regularly: clone from the backup, build the project, and confirm the latest commits and tags are there. A backup that has never been restored is a hope, not a backup.

An automated backup script

A minimal nightly backup, run from a server or a scheduled CI job on different infrastructure from your main platform:

backup-repos.shShell
#!/bin/sh
set -eu
date=$(date -u +%Y-%m-%d)
for repo in team/app team/website; do
  name=$(basename "$repo")
  rm -rf "/backups/work/$name.git"
  git clone --mirror "git@code.your-company.test:$repo.git" "/backups/work/$name.git"
  git -C "/backups/work/$name.git" lfs fetch --all || true   # skip if the repository has no LFS
  git -C "/backups/work/$name.git" bundle create "/backups/$name-$date.bundle" --all
  git bundle verify "/backups/$name-$date.bundle" > /dev/null
done
# Keep 30 days of bundles; copy them off-site with your storage tool of choice
find /backups -name '*.bundle' -mtime +30 -delete

Use a read-only deploy key or token for the clone, and make the job alert someone when it fails. LFS objects live in the mirror's lfs folder, not in the bundle, so copy that folder too.

Avoiding vendor lock-in

You can't avoid depending on a platform, but you can keep the cost of leaving low:

  • Keep build and test logic in scripts in the repository, with thin platform CI configuration (lesson 11).
  • Keep important documentation in the repository (README, CONTRIBUTING, architecture notes) rather than only in a platform wiki.
  • Prefer open formats and standard tools: plain Git, Markdown, standard package registries, OIDC rather than platform-only credentials.
  • Record decisions in commits and documents, not only in review threads, which may not survive a migration intact.
  • Know your exit path: run an occasional practice migration of one repository, and keep an up-to-date export of platform data.
  • Use platform-specific features deliberately: they're often worth it, but list them, so you know what a move would cost.

Common mistakes and troubleshooting

  • Cloning normally instead of with --mirror. Only the default branch is copied; other branches and many tags are missed.
  • Pushing to a destination that isn't empty. Create it without a README, license, or .gitignore.
  • Forgetting LFS objects. The new repository has pointer files with missing content. Push LFS separately.
  • "remote rejected ... refs/pull/..." during a mirror push. These are platform-owned refs; it's expected.
  • Mirrors that diverge. Make one side the source of truth; never accept pushes on both.
  • Backups never restored. Schedule a restore test, not only a backup job.
  • Updating code but not links. Search documentation, package metadata, and CI badges for the old URL.

Practical exercise: migrate, mirror, and restore

  1. Create a test repository with two branches, an annotated tag, and (optionally) an LFS file on one platform.
  2. Migrate it to a second platform with clone --mirror and push --mirror, then compare git ls-remote output for both.
  3. If the destination supports it, try its importer with issues and pull requests, and note what didn't transfer.
  4. Set up a push mirror (or a two-URL remote) so a new commit appears on both platforms.
  5. Create a bundle of the repository, verify it, restore it to a new folder, and build or open the project from the restored copy.
  6. Write a one-page exit plan for one of your real projects: what moves with Git, what needs an importer, and what must be recreated.

Key takeaways

  • Git history moves perfectly with clone --mirror and push --mirror; issues, reviews, CI, permissions, and releases need importers or recreation.
  • Verify migrations by comparing refs, and handle LFS objects separately.
  • Mirrors keep a live second copy; keep one source of truth.
  • Back up Git data, LFS objects, and platform data independently, with 3-2-1 copies, encryption, and regular restore tests.
  • Keep logic in scripts and documentation in the repository, so leaving any platform stays affordable.

References

What's next

You've finished the Git & Version Control series, from your first commit to running repositories in production. To make sure what you build works, continue with What Is Software Testing?, the first lesson of our testing series; to protect it, start What Is Web Security and Privacy? A Developer's Guide in our security series; or revisit What Is Version Control? whenever you need a refresher.

See every lesson in Git & Version Control: From Fundamentals to Advanced Workflows