【问题标题】:git remote -v : url is shown as ssh but it should be httpsgit remote -v : url 显示为 ssh 但它应该是 https
【发布时间】:2019-12-22 01:30:50
【问题描述】:

问题总结:

我正在尝试推送到 Github 上的远程存储库,但它给了我这个错误:

Warning: Permanently added the RSA host key for IP address
'192.30.253.112' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.*
Please make sure you have the correct access rights
and the repository exists.

我所做的背景:

我像往常一样通过获取 Github 上显示的 url 添加了一个远程仓库。我输入的命令是:

git remote add origin https://github.com/bowtie/myremote.git

然后我通过输入git remote -v 检查了我的远程存储库,即使我添加了一个https url,它也会显示在它们前面带有“ssh”的url:

git remote -v origin ssh://git@github.com/bowtie/myremote.git (fetch) origin ssh://git@github.com/bowtie/myremote.git (push)

然后我无论如何都尝试推送,此时它给了我我提到的错误:

git push --set-upstream origin master
Warning: Permanently added the RSA host key for IP address '192.30.253.112'
to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

为什么即使我将 url 添加为 https,它仍然显示 ssh?我尝试使用 git remote set-url 更改它,没有任何改变。我完全删除了 URL,然后读取了它,它仍然向其中添加了“ssh”。我检查了 git 配置文件,并且 URL 中正确写入了 https,那为什么它在命令行上显示 ssh?

顺便说一句,我有另一个遥控器,当我遇到这个问题时,我从本地 repo 中删除了 .git 文件并重新初始化它,然后创建了另一个遥控器,认为问题可能出在遥控器上。但问题仍然存在。我之前曾尝试从 https 更改为 ssh,但我无法获取密钥。现在,我只想让 git bash 在没有 ssh:// 的情况下向我显示正确的 URL 并推送我的提交。

【问题讨论】:

  • 您能否编辑您的问题以包含git config -l | grep insteadof 的输出?

标签: github ssh https rsa public-key


【解决方案1】:

我发现问题出在哪里。我之前使用了一个命令来用 ssh 替换每个 https,它适用于所有 git 操作。我通过修复 git config --global 文件来修复它。

我使用的命令是这样的: git config --global url."git@github.com:".insteadOf "https://github.com/"

解决方案是使用以下命令编辑配置全局文件: git config --global --edit 并手动删除该行

我发现这里解释的问题:https://discuss.bitrise.io/t/git-force-to-use-ssh-url-instead-of-https-for-github-com/4384

我找到了这里解释的解决方案:https://gist.github.com/taoyuan/bfa3ff87e4b5611b5cbe

【讨论】:

    猜你喜欢
    • 2018-10-18
    • 2019-10-27
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    相关资源
    最近更新 更多