马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
一、同时毗连多个git堆栈
1、创建多个ssh公私钥
- # 生成第一个 SSH 密钥对(用于第一个 GitLab 仓库)
- ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_gitlab_1
- # 生成第二个 SSH 密钥对(用于第二个 GitLab 仓库)
- ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_gitlab_2
复制代码 ~/.ssh/ 目次下创建两对文件:
- id_rsa_gitlab_1 和 id_rsa_gitlab_1.pub
- id_rsa_gitlab_2 和 id_rsa_gitlab_2.pub
2、将 SSH 公钥添加到 GitLab
对应.pub文件的内容添加到gitlab个人账户 ssh key
3、设置 SSH 客户端
- # 第一个 GitLab 仓库配置
- Host gitlab-repo1 #第一个仓库的别名
- HostName gitlab.com
- User git
- IdentityFile ~/.ssh/id_rsa_gitlab_1
- # 第二个 GitLab 仓库配置
- Host gitlab-repo2 ##第二个仓库的别名
- HostName gitlab.com
- User git
- IdentityFile ~/.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 堆栈
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
复制代码 三、git使用错误
初次毗连主机的安全验证,Git 会将该主机的公钥添加到本地的 ~/.ssh/known_hosts 文件中,确保以后毗连时不再提示。- The authenticity of host 'gitlab.glb.osl-nucleus.com (198.19.0.58)' can't be established.
- ED25519 key fingerprint is SHA256:2VcaaCmC4yv73cGnmcdVAL6+2UBqGexFMRS9SmCeL1Y.
- This key is not known by any other names.
- Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
- Warning: Permanently added 'gitlab.glb.osl-nucleus.com' (ED25519) to the list of known hosts.
- Connection closed by 198.19.0.58 port 22
- 致命错误:无法读取远程仓库。
- 请确认您有正确的访问权限并且仓库存在
复制代码 SSH 私钥没有精确加载
ssh-add -l:查抄当前署理中加载的密钥
ssh-add ~/.ssh/id_rsa:重新加载密钥
|