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

时间:2013-05-14 16:21:40

标签: ruby-on-rails git github ssh push

我无法通过此操作,多次重新创建存储库,将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 个答案:

答案 0 :(得分: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

答案 1 :(得分: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/

答案 2 :(得分:0)

要回答新错误:&#34;错误:src refspec master与any不匹配。错误:未能将某些引用推送到&#39; git@github.com:/demo_app0.git'

我发现此帖非常有用:src refspec master does not match any when pushing commits in git

基本上,请尝试添加文件并重新提交。

git commit -m 'initial commit' git push origin master

这对我有用!