解决git命令You must use a personal access token or SSH key的问题

今天在操作中遇到一个问题,如下

$git fetch upstream
Username for 'https://github.xyz.com': abcdefg
Password for 'https://abcdefg@github.xyz.com':
remote: Password authentication is not available for Git operations.
remote: You must use a personal access token or SSH key.
remote: See https://github.xyz.com/settings/tokens or https://github.xyz.com/settings/ssh
fatal: unable to access 'https://github.xyz.com/icp4d-sre/sre-infra.git/': The requested URL returned error: 403

其实之前我已经参照GitHub关于ssh配置的文档,配置好并已经使用了几个月,并没有遇到这个问题。经过查阅得知,是因为我的upstream是https格式而非ssh格式,如下:

$git remote -v
origin	git@github.xyz.com:abcdefg/sre-infra.git (fetch)
origin	git@github.xyz.com:abcdefg/sre-infra.git (push)
upstream	https://github.xyz.com/icp4d-sre/sre-infra.git (fetch)
upstream	https://github.xyz.com/icp4d-sre/sre-infra.git (push)

需要做的是通过git remote set-url upstream的命令,把https格式设置成ssh格式即可, 如下:

$git remote set-url upstream git@github.xyz.com:icp4d-sre/sre-infra.git
$git remote -v
origin	git@github.xyz.com:abcdefg/sre-infra.git (fetch)
origin	git@github.xyz.com:abcdefg/sre-infra.git (push)
upstream	git@github.xyz.com:abcdefg/sre-infra.git (fetch)
upstream	git@github.xyz.com:abcdefg/sre-infra.git (push)

$git fetch git@github.xyz.com:icp4d-sre/sre-infra.git
remote: Enumerating objects: 116, done.
remote: Counting objects: 100% (116/116), done.
remote: Compressing objects: 100% (99/99), done.
remote: Total 116 (delta 71), reused 57 (delta 17), pack-reused 0
Receiving objects: 100% (116/116), 94.33 KiB | 399.00 KiB/s, done.
Resolving deltas: 100% (71/71), done.
From github.ibm.com:icp4d-sre/sre-infra
 * branch            HEAD       -> FETCH_HEAD

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

飞鸿踏雪Ben归来

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

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

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

打赏作者

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

抵扣说明:

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

余额充值