在学习或工作的过程中,我们都会使用Git仓库来管理自己的代码,也会遇到Git仓库迁移的场景,下面教大家如何迁移Git仓库。
克隆一份裸版本仓库
git clone --bare 旧仓库地址
# 演示:git clone --bare https://github.com/codelong/demo01.git
这时会在当前目录下生成一个demo01.git的目录
进入仓库主目录
我们使用cd命令进入demo01.git目录
cd demo01.git
将旧仓库推送到新仓库
git push --mirror 新仓库地址
# 演示:git push --mirror https://gitee.com/codelong/demo01.git
等命令执行完成后,就可以在新仓库中看到所有的项目文件和记录了,我们的Git仓库迁移就完成了。