Return to site

🪞 Git “mirror” like a pro: duplicate a repo with everything (branches, tags, refs) — safely

September 21, 2025

Ever needed the same codebase in a brand-new repo without dragging along all the old wiring? Think: new brand/country, new org, or a clean slate with fresh tooling (Vault, CI/CD, Sonar, Artifact Registry, Helm/Terraform) — but preserve full history. That’s where --mirror shines.


Why --mirror?

  • Copies all refs (branches, tags, notes, remote-tracking) — not just the default branch.
  • git push --mirror makes the target exactly match your local mirror (adds/updates and deletes refs).
  • Perfect for one-shot duplication or setting up a read-only backup.

Quick recipe (from GitHub docs) âś…

Tip: git clone --mirror is an alternative to --bare that also sets mirror fetch/push config automatically.

Practical use cases đź’ˇ

  • Brand/Country forks without breaking company automation Spin up a new app with your platform’s generator (Vault/CI/CD/Sonar/etc.), then --mirror the code so you keep history but don’t inherit old integrations.
  • Org-to-Org migrations (e.g., GitLab âžś GitHub or between GitHub orgs) while keeping all branches/tags.
  • Disaster-recovery backups Push a scheduled --mirror to a secondary remote (GitHub mirror, CodeCommit, GitLab, Bitbucket).
  • Vendor handoffs / Legal splits Deliver complete history without exposing your original repo internals.
  • Freeze a baseline before diverging product lines (e.g., client-specific customization).

Gotchas & pro tips ⚠️

  • Target must be empty (or at least you should expect --mirror to overwrite refs).
  • Issues/PRs/Wiki/Releases metadata aren’t Git objects âžś they won’t mirror. Use platform import tools/APIs if you need them.
  • Git LFS? Do an LFS pass too:
  • Secrets & CI settings live in the platform, not the repo → reconfigure in the new project.
  • Submodules: update submodule URLs/remotes as needed.

Takeaways 🎯

  • --mirror = full-fidelity ref duplication (branches, tags, refs) — ideal for clean relocations and backups.
  • Use it when you want history intact but fresh platform wiring.
  • Be mindful: it overwrites the target’s refs and doesn’t bring over platform metadata (issues/PRs/secrets).
  • For LFS and CI, plan extra steps.

#Git #GitHub #GitTips #VersionControl #DevOps #SoftwareEngineering #CI #CD #DeveloperExperience #DX #Migration #Backup #GitLFS #Submodules