git push出现 “fatal: 发送请求时出错。”的一种特殊情况

问题描述

前提

ssh -T git@github.com 命令连接正常;

git clone、git pull 正常,github页面 `Settings/SSH and GPG keys` 确认已添加过本地ssh公钥。

注:git clone 出现类似问题的,可以考虑先移步git clone出现 fatal: unable to access 'https://github.com/...'的解决办法(亲测有效)_明天也要加油鸭的博客-CSDN博客

$ ssh -T git@github.com
Hi birdflyi! You've successfully authenticated, but GitHub does not provide shell access.

问题

git push 失败,提示fatal: 发送请求时出错,并报告不再支持密码认证方式,需要使用personal access token替代密码认证方式(然而前面已确认github页面添加过本地的ssh公钥)。

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git push --set-upstream origin main
fatal: 发送请求时出错。
fatal: 请求被中止: 未能创建 SSL/TLS 安全通道。
fatal: 发送请求时出错。
fatal: 请求被中止: 未能创建 SSL/TLS 安全通道。
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.
fatal: Authentication failed for 'https://github.com/birdflyi/Research-Methods-of-Cross-Science/'

remote报错:2021年8月13日,移除了对密码验证方式的支持。请改用个人访问令牌。

官方的解释:https://github.blog/changelog/2021-08-12-git-password-authentication-is-shutting-down/

已有相关博客解释说明此变化,并给出了配置github上的ssh Keys的方法[1]:GitHub不再支持密码验证解决方案:SSH免密与Token登录配置 - 爱码网

此博客还包含使用令牌的好处说明:GitHub不再支持密码验证解决方案:SSH免密与Token登录配置 - 爱码网

问题特征

特殊情况的特征在于:git remote -v 显示配置的url是http或https协议的,而配置的ssh需要使用git@github.com形式的ssh协议url。

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote -v
origin  https://github.com/birdflyi/Research-Methods-of-Cross-Science (fetch)
origin  https://github.com/birdflyi/Research-Methods-of-Cross-Science (push)

解决方案

综上,github的ssh Keys配置(详见[1]不再赘述)没有问题的情况下,将remote的url改成ssh所需的git@github.com形式即可。

即:

$ git remote remove origin 

$ git remote add origin git@github.com:birdflyi/Research-Methods-of-Cross-Science

实践中会有一些额外的操作才能使用默认的 git push 命令:

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote -v
origin  https://github.com/birdflyi/Research-Methods-of-Cross-Science (fetch)
origin  https://github.com/birdflyi/Research-Methods-of-Cross-Science (push)

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote remove origin

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote add origin git@github.com:birdflyi/Research-Methods-of-Cross-Science

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git remote -v
origin  git@github.com:birdflyi/Research-Methods-of-Cross-Science (fetch)
origin  git@github.com:birdflyi/Research-Methods-of-Cross-Science (push)

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main


Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git push --set-upstream origin HEAD:main
Everything up-to-date
branch 'main' set up to track 'origin/main'.

Adan@Adan-PC MINGW64 /e/gitRepo/Research-Methods-of-Cross-Science (main)
$ git push
Everything up-to-date

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bird_fly_i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值