思路:(前提:gogs和gitlab都已后台添加了ssh公钥)

           a、从gogs下载仓库到本地

           b、再在本地checkout所有分支下来

           c、删除gogs的远程链接

          d、添加gitlab的远程链接

          e、上传本地仓库至gitlab

1、本地生成ssh公钥,~/.ssh/id_rsa.pub 生成之后,将此文件内容复制到gitlab中

[root@localhost ~]# ssh-keygen -o       #一路回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:yKngQDH2OP3TJQH+JkFXh8WiXRFlvJ42n0zgf+K8plo root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| + o.o..+==o |
|. * o . .o.o.. |
| + o o .o.o . |
|. . ..++o. o |
|. . +++S o o |
| o . .+ * . |
| . . E * .|
| . .o=.|
| ...++o.|
+----[SHA256]-----+


[root@localhost ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDEAifrSLHZBG74ckYMJ1k6meWDxkxI+8KLicyoi/DrCQxMEQ5IO/1Fc89Zk+9W5jdjwPyhy3L/goehtkSf233UFbYD5pzrJA1VdZmnkiB3aZevbMcplBs0/VAkjXrRRbPs1zItRZXwwBS+E6hA0/Abv2luhA+qCRON3avwFCbpUadfXlheu4a8Q9L0eIN1GUYt7MQ81CH0zDwAA0dK4B494XK9KnQuc26WC783fvvug14IlVAN4ybIOj8XleE5wQeJnsHzYknJmdke+6HXelqNoEWye4xMG2ycknH86W0hB8RCM6GfPnRdhek2mjwFx9MryY/wRqjFZmIlzWIXyqrh root@localhost.localdomain

 

2、将公钥添加至gitlab中

gogs迁移仓库至gitlab_gitlab

 

3、在本地下载gogs仓库,checkout所有分支并上传到gitlab,例如仓库名为TESTA,git用户名为gogs(这个用户需要对TESTA仓库有权限)

[root@localhost ~]# git clone git.com:gogs/TESTA   #克隆gogs上的仓库到本地
[root@localhost ~]# cd TESTA #进入到仓库目录
[root@localhost ~]# git branch -r #查看所有远程仓库
[root@localhost ~]# git branch -r | grep -v '\->' | while read remote;do git branch --track "${remote#origin/}" "$remote";done #checkout所有分支到本地
[root@localhost ~]# git fetch --all
[root@localhost ~]# git pull --all
[root@localhost ~]# git remote rm origin #删除本地gogs仓库的链接信息
[root@localhost ~]# git remote add origin git@gitlab.com:gogs/TESTA.git #添加gitlab仓库链接,其中的gogs为用户名,TESTA为仓库名,推送时gitlab会自动创建
[root@localhost ~]# git push -u origin --all #上传仓库到gitlab
[root@localhost ~]# git push -u origin --tags #上传tags到仓库