Push failed: Failed with error: fatal: Could not read from remote repository.

昨天做了一个梦, 发现辛苦码的代码被自己sudo rm -rf / 了, 梦里面内心万千草泥马奔腾而过, 醒来的时候发现眼角还有几滴余泪.

今天果断掏出重器 Git, 把代码放在仓库中, 再也不用担心手残了.(用idea果断去搞了一波)

没错, 碰了一鼻子灰, 还被打的鼻青脸肿.

Push failed: Failed with error: fatal: Could not read from remote repository.(没错, 就是它, 太坏了)

错误原因: ssh 有自己的规矩, 没有设置key就没法连接上github

完整过程:

请确保以下2步均做到

1、远程服务器已经有了对应于本地主机上公钥

2、本地主机ssh服务开启(windows上是ssh-agent.exe运行),并且本地主机私钥要包含在ssh服务列表中

 

具体细节:

为远程服务器(heroku)添加公钥的方法:可以到~/.ssh 下查看是否存在密钥对,如id_rsa和id_rsa.pub,可以

直接运行  

 

heroku keys:add

 

 

如果不存在的话,打命令生成一对

 

ssh-keygen -t rsa

 

然后再

 

heroku keys:add

 

 

检查本地私钥是否存在于ssh服务中

 

 

eval `ssh-agent -s`

如果运行这句出现Could not open a connection to your authentication agent,那么就先运行

 

 

ssh-agent bash


再运行

 

 

ssh-add -l

 

 
如果不存在,需要添加进去
 
ssh-add ~/.ssh/id_rsa
如果是push到git的话,给git添加公钥的话,可以手动把~/.ssh/id_rsa.pub的内容复制好,然后如下

 

Now that you have the key copied, it's time to add it into GitHub:

  1. Account settings buttonIn the user bar in the top-right corner of any page, click Account settings.
  2. SSH Keys menuClick SSH Keys in the left sidebar.
  3. SSH Key buttonClick Add SSH key.
  4. In the Title field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air".
  5. The key fieldPaste your key into the "Key" field.
  6. The Add key buttonClick Add key.
  7. Confirm the action by entering your GitHub password.

 

 

然后就可以创建本机Git仓库, 上传到Github

1、配置idea

这里写图片描述

2、idea上创建本地仓库

这里写图片描述

3、项目变红,然后Git–>Add

这里写图片描述

add后变绿 
这里写图片描述

4、提交到本地

这里写图片描述

最后share project on github

收工:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来日可期1314

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值