使用git push --mirror后新仓库提交同步至旧仓库的问题求助
问题解决指南
1. 清理本地仓库的远程关联
先排查本地仓库是否同时绑定了新旧两个远程地址,这是提交同步到旧仓库的常见原因:
- 查看当前远程仓库列表:
git remote -v - 如果发现旧仓库的远程地址(比如
origin指向旧仓库),直接移除:git remote remove origin # 若旧仓库用了其他远程名,比如old-repo,就执行 git remote remove old-repo - 确保本地只绑定新仓库的远程:
git remote set-url origin https://new-parent-cicd-pipeline.git
2. 取消新仓库的GitHub镜像同步
使用git push --mirror推送时,可能会在GitHub自动创建镜像同步规则,导致提交反向同步到旧仓库:
- 打开新仓库的Settings页面,找到Repository > Mirroring repositories
- 如果有指向旧仓库的镜像条目,直接删除即可
3. 更新新仓库的pom.xml配置
手动修改pom里的groupId、artifactId和SCM连接:
- 编辑本地pom.xml,替换对应字段:
<groupId>你的新groupId</groupId> <artifactId>你的新artifactId</artifactId> <scm> <connection>scm:git:https://new-parent-cicd-pipeline.git</connection> <developerConnection>scm:git:https://new-parent-cicd-pipeline.git</developerConnection> <url>https://new-parent-cicd-pipeline.git</url> </scm> - 提交并推送到新仓库:
git add pom.xml git commit -m "Fix pom.xml groupId, artifactId and SCM settings" git push origin main # 替换成你的主分支名称,比如master
4. 删除新仓库的安全性说明
删除新仓库完全不会影响旧仓库。两个仓库是GitHub上独立的实体,只要没有手动设置的同步规则,删除操作只会作用于新仓库,旧仓库的所有内容都不会被改动。
5. 验证关联是否彻底解除
做个简单测试确认:
- 本地新建测试文件并推送:
echo "unlink test" > verify.txt git add verify.txt git commit -m "Verify unlink status" git push origin main - 去旧仓库查看,如果没有出现这个测试提交,说明关联已经完全解除。
内容的提问来源于stack exchange,提问作者Robo
相关产品推荐
相关产品推荐

