首页/开发/Git 与协作速查/git clone --mirror 镜像克隆
Git 基础与命令88 条

git clone --mirror 镜像克隆

镜像克隆得到包含全部引用(分支、标签与远端配置)的裸仓库,常用于仓库迁移与站点镜像,配合 push --mirror 整体推送。

Git 与协作速查开发更新于 2026-10-12
用途仓库迁移、镜像与冷备份
产物裸仓库 + refs/* 全量引用
推送git push --mirror <目标>

常用示例

常用示例
git clone --mirror git@example.com:team/repo.git repo-mirror.git
cd repo-mirror.git
git push --mirror git@example.com:team/newrepo.git
git show-ref | wc -l
镜像仓库包含 refs/remotes 等全部引用,推送到目标前确认目标库是否允许覆盖;refs/pull 类临时引用可能一并带上。

易错点

  • --mirror 的 fetch refspec 是 +refs/*:refs/*,之后每次 fetch 都会强更新,普通开发不要用镜像仓库当工作副本
  • 迁移后用 git show-ref 对比源库与目标库引用数量,避免漏掉分支或标签

数据来源与参考

  • Git 官方文档:git-clone(--mirror)
  • Git 官方文档:git-push(--mirror)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌