昨天做了一个梦, 发现辛苦码的代码被自己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:
In the user bar in the top-right corner of any page, click Account settings.
Click SSH Keys in the left sidebar.
Click Add SSH key.- 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".
Paste your key into the "Key" field.
Click Add key.- Confirm the action by entering your GitHub password.
然后就可以创建本机Git仓库, 上传到Github
1、配置idea

2、idea上创建本地仓库

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

add后变绿 
4、提交到本地

最后share project on github
收工:
本文分享了一位初学者在使用Git过程中遇到的Push失败问题及解决方案,详细介绍了SSH密钥的生成、添加以及如何正确配置本地Git仓库与远程仓库的连接,适合所有遇到类似问题的开发者阅读。
6761

被折叠的 条评论
为什么被折叠?



