git报错 ssh: Could not resolve hostname gitee.com:xxxxxx: Name or service not known fatal

问题

使用git进行push操作时突然出问题,报错如下:

ssh: Could not resolve hostname git: xxxxx: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.

 查了大半天,有的说重新配置ssh公钥,重新配置了好几遍,都没用,问题依旧。

有的说 在/etc/hosts文件中添加配置ip,因为hosts文件不太好修改,要管理员权限,好不容易修改成功了,还是没用( o(╥﹏╥)o ,网上很多这个解决方案的,真坑 )。

百度了大半天最终决定去谷歌试试,终于在谷歌搜索到一个解决方案:

Change the [remote "origin"] url value in .gitconfig or .config/git/config file

Previously:

https://git@github.com:userName/repo.git

OR

ssh://git@github.com:userName/repo.git

New:

git@github.com:userName/repo.git

(原文:https://stackoverflow.com/questions/53129706/ssh-could-not-resolve-hostname-git-name-or-service-not-known-fatal-could-not

解决方案

就是修改.git下的config文件,将[remote "origin"]下的url从原来的

https://git@github.com:userName/repo.git 或 ssh://git@github.com:userName/repo.git

修改为:

git@github.com:userName/repo.git

我原来是:https://gitee.com/xxxx/xxxxx.git

修改后如下:

问题最终解决!

问题分析

之所以会出现这样的问题,应该是本来没有配置ssh公钥,后面配置了,

origin数据源原来是https的,需要换成ssh的才行。

附git数据源的三种修改方式:

方式1. 修改命令
git remte origin set-url URL


方式2. 先删后加
删除命令: git remote rm origin
添加命令: git remote add origin git@github.com:Liutos/foobar.git


方式3. 直接修改config文件

  • 15
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值