本文介绍git常见报错, 记录自己遇到的报错的同时, 指引可能也遇到同样问题的读者

Permission denied

情况1

问题描述:

1
2
3
4
5
6
7
8
9
10
11
12
git clone git@github.com:***.git

Cloning into '***'...
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

问题原因: clone了别人的仓库, 用的git链接

解决方法: 改用http链接即可

情况2

问题描述

1
2
3
4
git push orgin master

! [remote rejected] master -> master (permission denied)
error: failed to push some refs to 'git@github.com:ericjuice/overlaySR.git'

问题原因: push错仓库了或者没有设置ssh. 我这里是前者, 由于我同一台机器存在2个不同的github账号的不同的ssh key, push的时候push错了仓库

解决方法: 修改push的URL, 或者修改ssh设置, 让git寻找到正确的仓库即可

Connection refused

问题描述1:

1
2
3
4
git clone https://github.com/***.git

Cloning into '***'...
fatal: unable to access 'https://github.com/***.git/': Failed to connect to 127.0.0.1 port 15777: Connection refused

问题原因: 这是在本地出的错, 应该是权限问题

解决方法: 加个sudo即可

Connection reset

问题描述:

1
2
3
4
5
6
7
git push  origin master

kex_exchange_identification: read: Connection reset by peer
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

问题原因: ssh key错误或者url填错或者是自己网络问题

解决方法: 手动更新一下本地和github上的ssh key, 或者把科学上网换一下试试