今天在操作中遇到一个问题,如下
$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
|