无法推送到Github,ssh:无法解析主机名。

15
我无法通过此步骤,已经重复创建了多个存储库,重新生成了ssh密钥。
--------------
demo_app <username>$ git remote add origin git@github.com:<username>/demo_app.git

fatal: remote origin already exists.

$ git push -u origin master
---
ssh: Could not resolve hostname git: nodename nor servname provided, or not known
---
fatal: Could not read from remote repository.
---
Please make sure you have the correct access rights
---
and the repository exists.
----------
---------

Checked ssh keys

---

$ ssh -T git@github.com

Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.

---

仍然收到相同的消息。

3个回答

16

不要添加新的远程,而是尝试使用以下命令更改现有远程:

git remote set-url origin git@github.com:<username>/demo_app.git

编辑:以下是命令,可使其正常工作而不会丢失您的代码:

  1. rm -rf .git
  2. git init .
  3. git remote add origin git@github.com:<username>/demo_app.git
  4. git commit --allow-empty -m 'First commit'
  5. git push origin master

之前尝试过,结果发现我没有在操作前执行 $ git add .。我试图重复之前的操作以获取错误信息,但是出现了一个不同的错误:“错误:源参考规范 master 不匹配任何内容。 错误:无法将某些引用推送到 'git@github.com:<username>/demo_app0.git'。” - A Ali

6

如果您因为使用代理而来到这里

请尝试:

ssh -T -p 443 git@ssh.github.com

如果这样做有效,那么您可以将设置添加到您的~/.ssh/config中,以始终通过443连接:
Host github.com
  Hostname ssh.github.com
  Port 443 

更多信息请点击此处: https://help.github.com/articles/using-ssh-over-the-https-port/。 该链接介绍了如何在HTTPS端口上使用SSH。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接