likes
comments
collection
share

06.git push错误:ssh:Could not resolve hostname gitee.com:Name or service not known

作者站长头像
站长
· 阅读数 7

因为最近学习Vue.js接触到了很多新东西,所以遇到了各种问题,下面这个问题是我将本地项目上传到远程仓库时遇到的问题,希望对大家有帮助。 git push错误:ssh:Could not resolve hostname gitee.com:Name or service not known fatal:Could not read from remote respository

图片:06.git push错误:ssh:Could not resolve hostname gitee.com:Name or service not known

解决方法一:

  1. 检查是否创建SSH公钥,如生成公钥则进行下一步。
  2. 检查该项目文件是否是从远程仓库(码云/GitHub)上Clone下来的,如果不是则用此方法。
  3. 在远程仓库(码云/GitHub)上创建项目同名的库。
  4. 将项目里的文件除(README.mdREADME.en.md,.git文件夹)复制到clone下来的文件中
  5. 选中文件右键点击git bash
  6. 输入git add . 06.git push错误:ssh:Could not resolve hostname gitee.com:Name or service not known
  7. 输入git commit -m “项目描述” 06.git push错误:ssh:Could not resolve hostname gitee.com:Name or service not known
  8. 输入git push 06.git push错误:ssh:Could not resolve hostname gitee.com:Name or service not known 成功上传!

解决方法二:

  1. 检查是否创建SSH公钥,如生成公钥则进行下一步。

  2. 检查该项目文件是否是从远程仓库(码云/GitHub)上Clone下来的,如果是则用此方法。

  3. 解决方式1: **step1. ping github.com 获取到github.com的ip为192.30.252.128 step2. 在/etc/hosts中添加一行如下: 192.30.252.128 github.com**

  4. 解决方式2: 以root权限执行如下python代码

    import socket
    
    host = 'github.com'
    
    try:
        with open('/etc/hosts', 'a+') as fp: 
            ip = socket.gethostbyname(host)
            fp.write(' '.join([ip, host, '\n']))
    except BaseException as e:
        print(e)
    else:
        print('sucess')
    

    我试了上面的方法,好像都不奏效,最后检查了远程地址,git remote -v,

    然后删除了远程地址,git remote rm 别名

    最后重新绑定来了远程仓库的地址,git remote add origin gitee远程仓库地址(因为远程仓库地址改变了)

    然后再次推送远程库,git push origin master,

    成功了!!!

转载自:https://juejin.cn/post/7006109959486193700
评论
请登录