git连不上ssh头壳疼

最近有做到一道很有意思的git练习题

  •  oops_2021 fork到自己的项目里。

  •  fork 后的远程仓库 clone 下来,并在 ./src 里创建一个文件夹,文件夹名为 Github 的用户名,并在文件夹内存放一个文件。

  • 存放的文件内容可以是(文件大小不宜太大):其他题目的文件,可选任务的代码文件

  • 将修改后的项目提交到你 fork 的远程仓库。

  • 当你确定你不会再更改远程仓库的时候,提交合并请求到主项目。(当然你提交后还是可以修改再次提交)

 首先是零基础了解git

当我做好后满心欢喜的使用Terminal合并提交到远程仓库上时:

git push origin报错:

Could not read from remote repository.Please make sure you have the correct access rights

首先git输入命令:$ ssh-keygen -t rsa -C "your@email.com"(忘了注册邮箱可以去github的account上找一下)

如果执行成功,返回:

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/username/.ssh/id_rsa):

输入你想要该随机密钥文件保存的名称,按回车结束。再打开该文件,全文复制。

打开github官网登陆自己的账户,进入设置,点击SSH and GPG keys打开该页面,把刚才复制的粘贴在key中(mac上可以用command+空格跳查刚刚生成的文件)

 

title可以不填,最后点击add ssh key。在git中输入:ssh -T git@github.com,输入命令yes,回车。

同时可能会有如下问题

fatal: remote origin already exists

解决:

1先删除远程Git仓库

git remote rm origin

2再添加远程Git仓库

git remote add origin url(要添加的远程仓库地址)

本以为就这样结束了,仓库又出现了问题

 git push origin 时遇到报错如下:

fatal:'origin' does not appear to be a git repository

fatal:Could not read from remote repository

解决方案

0、cd 本地分支
1、git branch 
            2、git remote –v
             
3、git remote add origin ssh://git@***.git(地址)
4、git fetch origin  
5、git remote –v
6、git branch –a

 如果可以了,再重复步骤1

参考:

git提交出现”Could not read from remote repository.Please make sure you have the correct access rights”错误

fatal:‘origin‘ does not appear to be a git repository fatal:Could not read from remote repository

MacOSgit clone git@github.com: Permission denied publickey)錯誤及解決方式

posted @ 2021-10-27 09:28  百花苑的小破鱼  阅读(405)  评论(0)    收藏  举报