您的位置:首页 > 财经 > 金融 > 制作图_济南app开发公司哪家好_四川旅游seo整站优化站优化_太原网站快速排名优化

制作图_济南app开发公司哪家好_四川旅游seo整站优化站优化_太原网站快速排名优化

2025/5/9 17:46:04 来源:https://blog.csdn.net/xiazaizhuanyong1231/article/details/145308646  浏览:    关键词:制作图_济南app开发公司哪家好_四川旅游seo整站优化站优化_太原网站快速排名优化
制作图_济南app开发公司哪家好_四川旅游seo整站优化站优化_太原网站快速排名优化

一、同时连接多个git仓库

1、创建多个ssh公私钥

# 生成第一个 SSH 密钥对(用于第一个 GitLab 仓库)
ssh-keygen -t rsa -b 4096 -C "your-email@example.com" -f ~/.ssh/id_rsa_gitlab_1# 生成第二个 SSH 密钥对(用于第二个 GitLab 仓库)
ssh-keygen -t rsa -b 4096 -C "your-email@example.com" -f ~/.ssh/id_rsa_gitlab_2

~/.ssh/ 目录下创建两对文件:

  • id_rsa_gitlab_1id_rsa_gitlab_1.pub
  • id_rsa_gitlab_2id_rsa_gitlab_2.pub

2、将 SSH 公钥添加到 GitLab

对应.pub文件的内容添加到gitlab个人账户 ssh key

3、配置 SSH 客户端

# 第一个 GitLab 仓库配置
Host gitlab-repo1 #第一个仓库的别名HostName gitlab.comUser gitIdentityFile ~/.ssh/id_rsa_gitlab_1# 第二个 GitLab 仓库配置
Host gitlab-repo2 ##第二个仓库的别名HostName gitlab.comUser gitIdentityFile ~/.ssh/id_rsa_gitlab_2

4、配置 Git 远程仓库

# 对于第一个仓库(使用第一个 SSH 密钥)
git remote set-url origin git@gitlab-repo1:username/repo1.git# 对于第二个仓库(使用第二个 SSH 密钥)
git remote set-url origin git@gitlab-repo2:username/repo2.git

gitlab-repo1:步骤3、配置 SSH 客户端中对应的仓库别名

username:gitlab中的账号

repo1.git:gitlab工程路径

5、测试是否成功

# 测试第一个仓库的连接
ssh -T git@gitlab-repo1# 测试第二个仓库的连接
ssh -T git@gitlab-repo2

如果设置正确,您会看到类似以下的消息:

Welcome to GitLab, @username!

二、本地git工程推送到新的gitlab仓库

1、初始化本地 Git 仓库

git init

2、将代码添加到 Git 版本控制中

git add .
git commit -m "首次提交"

3、创建远程仓库

在 GitHub、GitLab 等平台上创建新的project。

4、本地仓库与远程仓库关联

将本地仓库与远程仓库关联,类似第一种方式:

git remote add origin <远程仓库地址>

如果本地工程已经是git工程,需要关联到新的git仓库,忽略前面1、2步

git remote add new-origin <新的远程仓库地址>

5、推送到远程仓库

git push -u origin master # 或 main

如果需要推送到新的远程仓库:

git push -u new-origin master  # 或者 main

推送报错如下,有可能是Git 缓冲区太小:

Pushing to https://gitlab.****.git
Enumerating objects: 5594, done.
Counting objects: 100% (5594/5594), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2777/2777), done.
POST git-receive-pack (chunked)4)
error: RPC failed; HTTP 500 curl 22 The requested URL returned error: 500
send-pack: unexpected disconnect while reading sideband packet
Writing objects: 100% (5594/5594), 65.66 MiB | 98.58 MiB/s, done.
Total 5594 (delta 2037), reused 5520 (delta 1998), pack-reused 0
fatal: the remote end hung up unexpectedly

修改缓存区大小

git config http.postBuffer 524288000

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com