在我为我的 repo 从 HTTPS 切换到 SSH 之后,我在推送到 origin master 时收到了这个错误:
ssh: Could not resolve hostname git: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
我还在 gitlab 中添加了我的 ssh。我该怎么办?
Shi*_*rma 16
我遇到了同样的错误。
更改或文件中的[remote "origin"]
url
值.gitconfig
.config/git/config
之前:
https://git@github.com:userName/repo.git
或者
ssh://git@github.com:userName/repo.git
新的:
git@github.com:userName/repo.git
Dhr*_*shi 11
HTTPS URL 提供对私有或公共存储库的轻松访问,即使您在防火墙或代理后面工作。这是推荐的方式。
另一方面,SSH URL 使用安全的 ssh 协议来访问存储库。
回到你的问题,错误很可能是因为配置不当。该git remote add
命令用于向您的存储库添加一个您已经尝试过的新遥控器。但是,从 HTTPS 切换到 SSH url,意味着您的远程源已经设置为 http url 并且您想要更改。
因此,首先检查您当前的远程源所指的网址:
$ git remote -v
Run Code Online (Sandbox Code Playgroud)
如果它指的是 HTTPS 网址,那么您必须使用
$ git remote set-url origin mySSH_url
Run Code Online (Sandbox Code Playgroud)
命令将其更改为 SSH url。
现在,尝试git remote -v
,它将显示为 origin 配置的 SSH url。
请确保在使用 SSH url 时,您已经ssh-agent
在 GitLab/GitHub 帐户上生成并添加了 ssh 密钥。
这是一篇关于如何更改遥控器网址的非常好的文章。
此外,您可以在此处了解有关使用哪个远程 url 的更多信息。
小智 6
我在使用 azure 时遇到了同样的问题。
ssh: Could not resolve hostname ssh.abc.azure.com: Temporary failure in name
resolution
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
exists.
Run Code Online (Sandbox Code Playgroud)
原因:该问题是由于WSL2失败造成的。
修复: 禁用并启用 WSL。
归档时间: |
|
查看次数: |
82108 次 |
最近记录: |