git 仓库迁移

场景1:git仓库无lfs

仓库地址
旧仓库地址 http://gitee.com/original/git_repository.git
目标仓库地址 http://gitee.com/target/git_repository.git

迁移命令

git clone --bare http://gitee.com/original/git_repository.git
cd git_repository.git
git push --mirror http://gitee.com/target/git_repository.git

样例如下:

cxloge@DESKTOP-HPL3DI2 MINGW64 ~/Desktop/git_move
$ git clone --bare http://gitee.com/original/git_repository.git
Cloning into bare repository 'RaspberryPi4.git'...
remote: Enumerating objects: 342, done.
remote: Counting objects: 100% (342/342), done.
remote: Compressing objects: 100% (317/317), done.
remote: Total 342 (delta 51), reused 179 (delta 19), pack-reused 0
Receiving objects: 100% (342/342), 19.11 MiB | 3.78 MiB/s, done.
Resolving deltas: 100% (51/51), done.

cxloge@DESKTOP-HPL3DI2 MINGW64 ~/Desktop/git_move
$ cd git_repository.git

cxloge@DESKTOP-HPL3DI2 MINGW64 ~/Desktop/git_move/git_repository.git (BARE:master)
$ git push --mirror http://gitee.com/target/git_repository.git
Enumerating objects: 342, done.
Counting objects: 100% (342/342), done.
Delta compression using up to 4 threads
Compressing objects: 100% (285/285), done.
Writing objects: 100% (342/342), 19.11 MiB | 887.00 KiB/s, done.
Total 342 (delta 51), reused 342 (delta 51), pack-reused 0
remote: Resolving deltas: 100% (51/51), done.
remote: Powered by GITEE.COM [GNK-6.4]
To http://gitee.com/target/git_repository.git
 * [new branch]      master -> master

更改Git远程仓库地址

git remote -v # 查看git远程仓库地址
git remote set-url origin http://gitee.com/target/git_repository.git # 替换成新地址
git remote add origin-new http://gitee.com/new/git_repository.git # 添加新地址
git remote -v # 查看是否更新成功

样例如下:

cxloge@DESKTOP-HPL3DI2 MINGW64 ~/Desktop/git_move/RaspberryPi4.git (BARE:master)
$ git remote -v
origin  http://gitee.com/original/git_repository.git (fetch)
origin  http://gitee.com/original/git_repository.git (push)

cxloge@DESKTOP-HPL3DI2 MINGW64 ~/Desktop/git_move/RaspberryPi4.git (BARE:master)
$ git remote set-url origin http://gitee.com/target/git_repository.git

cxloge@DESKTOP-HPL3DI2 MINGW64 ~/Desktop/git_move/RaspberryPi4.git (BARE:master)
$ git remote -v
origin  http://gitee.com/target/git_repository.git (fetch)
origin  http://gitee.com/target/git_repository.git (push)

场景2:git lfs仓库迁移

仓库地址
旧仓库地址 http://gitee.com/original/git_lfs_repository.git
目标仓库地址 http://gitee.com/target/git_lfs_repository.git
git clone --bare http://gitee.com/original/git_lfs_repository.git	
cd git_lfs_repository.git	
git lfs fetch --all	#将 LFS 的文件都下载到本地
git remote add origin-target http://gitee.com/target/git_lfs_repository.git
git lfs push --all origin-target	# 推送 LFS 文件到origin-target
git push --mirror origin-target	

样例如下:

待后续补充

参考文章

  1. git仓库迁移所有分支脚本_郑清的博客-CSDN博客_git 迁出分支
    https://blog.csdn.net/qq_38225558/article/details/125299816

  2. git仓库迁移所有分支脚本
    可参考:https://gitee.com/zhengqingya/shell

  3. 如何修改项目中Git远程仓库地址?
    https://blog.csdn.net/xutong_123/article/details/128021440

posted on 2023-03-11 15:35  cxloge  阅读(46)  评论(0编辑  收藏  举报