文章目录

  • 一、报错信息
  • 二、解决方案

一、报错信息


在 Android Studio 中首次向 GitHub 提交代码 , 报错 :

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

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_git

二、解决方案


将 设置中的 Git 的 SSH executable 设置为 Native ;

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_android_02

打开 Git 安装目录下的 bin/bash , 在命令行中输入

ssh-keygen -t rsa -C "han1202012"

其中 han1202012 是 GitHub 账号 ;

点击 3 3 3 次回车 ;

octopus@DESKTOP-0EUIENB MINGW64 /bin
$ ssh-keygen -t rsa -C "han1202012"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/octop/.ssh/id_rsa):
Created directory '/c/Users/octop/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/octop/.ssh/id_rsa.
Your public key has been saved in /c/Users/octop/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pklRhEXgBzBDx3+zYponKSlrK7JsAPTncT78O6hGp4A han1202012
The key's randomart image is:
+---[RSA 3072]----+
| .=o+*= |
| . =oo |
|. . o.. |
|. . o +. o |
|. . o * S. o |
|.E . + Oo . |
|. o.==+. |
|+.o oo=..o |
|+=o+.o.o .o |
+----[SHA256]-----+

octopus@DESKTOP-0EUIENB MINGW64 /bin
$

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_android_03

进入 C:\Users\octop\.ssh 目录 , 需要使用 id_rsa.pub 中的内容 ;

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_github_04

C:\Users\octop.ssh\id_rsa.pub 文件的内容为 :

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDl+Ph2KiYOx3ABXGowLzB8Mb4uz7NcEaK0xfxzeTb173QWjSNC0H61nkP1aZX94A2r83kO1dIHoHSwxalGRLh6wL9vUJUq/XqvLGxUjcPDTVgztU/RR9Sw2aVFTPE9nWcZHvysnC3ST37iRMj+kUc2eWZ15UjgUZ+5xNh+e5kh80JAtJrJTSmyeyTI42UllGmDtVK0QWZAIylIcB2pS2vUDbrQFDtJOfIF6GvTReTWxQNH611TaQ+bIQpm9PgIcodO/vAWqer7i8xGv0BRObdUsl7ACq3FJOFuLsOqeR5DJVdgMcInP+tHO6dPFrQ6kX24a9oixpkOKaqK/rb7cH0xqUR0mlxtSe2EavnfmDhK1ejesbSYPH93Den92izhrW212fQMtKGrIxon1aaaRuIZnO1uccOzbfAnSz7F9SiyqAPvY03TlotHTlbMsTRPtjlNj6A4sxT9WbxdbZjanPplfgVhps1GLno3l91XZNXXO/Nq+VejK00ktUa5dbWQDi0= han1202012

进入到 GitHub 中 ;

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_android_05

进入提交错误的工程的额 Settings 选项 ;

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_原力计划_06

选择 Deploy Keys 选项卡 , 然后点击 " Add deploy key " 按钮 ;

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_github_07

将 C:\Users\octop.ssh\id_rsa.pub 文件的内容拷贝到 Key 中 ;

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_github_08

设置完毕 ;

【错误记录】Android Studio 向 GitHub 提交代码报错 ( Push failed: Failed with error: Could not read from remote )_desktop_09