有时候我们为了保证仓库代码安全或者对代码进行同时开源发布,可能将git代码传送到两个不同的git代码仓库。接下来演示下如何进行操作:
首先咱们需要有Gitee的仓库以及Github的仓库
https://gitee.com/cynthia99/lanqiao.git
https://github.com/986515470/lanqiao-codes.git
已存在的话,先从一个仓库中将代码clone下来
git clone https://gitee.com/cynthia99/lanqiao.git
删除仓库origin
git remote rm origin
关联两个远程仓库
# 关联gitee
git remote add gitee https://gitee.com/cynthia99/lanqiao.git
git push gitee master
# 关联github
git remote add github https://github.com/986515470/lanqiao-codes.git
git push github master
但如果出现下面这种情况
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/cynthia99/lanqiao.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
此时要先执行:(先pull再push)
git pull github master --allow-unrelated-histories
当出现了下面这种情况时:
PS C:\Java\SpringBootExe\lanqiao> git push github master
fatal: unable to access 'https://github.com/986515470/lanqiao-codes.git/': OpenSSL SSL_read: Connection was reset, errno 10054
修改设置,解除ssl验证:
git config --global http.sslVerify "false"
当遇见下面这种情况时,则是需要github验证登录。 可以在弹出来的窗口中选择账号密码登录,也可以选择token验证登录
PS C:\Java\SpringBootExe\lanqiao> git push github master
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
如果出现如下错误:
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
根据提示信息可以知道,github 在 2021.8.13 移除了密码认证的支持,它建议使用 personal access token
代替密码认证。由于提示中给出的地址无法访问,所以查阅相关文档,下面主要记录一下如何解决这个问题
github docs 文档中描述说,在使用命令行或API的时候,应该创建一个个人访问令牌(personal access token)来代替密码,下面详细介绍如何创建 personal access token。
警告:将您的令牌视为密码并保密。使用 API 时,将令牌用作环境变量,而不是将它们硬编码到您的程序中。
个人访问令牌只能用于 HTTPS Git 操作。如果您的存储库使用 SSH 远程 URL,则需要将远程从 SSH 切换到 HTTPS。
如果系统未提示您输入用户名和密码,则您的凭据可能已缓存在您的计算机上。您可以更新钥匙串中的凭据以使用令牌替换旧密码。
此处评论已关闭