如何解决git push/pull操作时出现的Operation timed out
文章目录
最近git push时常出现Operation timed out,具体内容大概如下:
$ git push origin 72
ssh_dispatch_run_fatal: Connection to 192.30.255.112 port 22: Operation timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.意思是说:在连接远程地址的22端口时超时了,然后要检查权限和远程仓库是否存在。
首先在网页端是可以访问到该仓库的,所以问题并没有出在提示的权限或远程仓库。
解决步骤
查看远程仓库地址
查看项目下的.git/config文件,注意.git文件夹是隐藏文件夹。
[remote "origin"]
url = git@github.com:yunzhiclub/xxxx.git
fetch = +refs/heads/*:refs/remotes/origin/*得出远程仓库的地址是github.com
SSH
$ ssh github.com
panjie@github.com: Permission denied (publickey).提示权限不允许,确认网络能够访问远程主机22端口。如果不能访问,那么需要在网络上找原因了。第一先看是否能ping通,如果能ping通,则看防火墙策略是否禁用了ssh连接或22端口。
ping
网络没有问题,那问题就应该出现在证书上了。
ping github.com
panjieIMacdeiMac:app panjie$ ping github.com
PING github.com (192.30.255.112): 56 data bytes
64 bytes from 192.30.255.112: icmp_seq=0 ttl=36 time=297.969 ms得到github.com的ip地址为192.30.255.112。
vi ~/.git/known_hosts
找到github.com,xx.xx.xxx.xxx的一条,发现xx.xx.xxx.xxx与192.30.255.112并不一致,删除。
问题解决。
总结
git不上去可能是由以下原因造成的:
- 仓库不存在或没有权限。验证:进行网页端登录。
- 网络问题。验证:ping一下看通不通。
- ssh或端口问题。验证:
ssh github.com,看提示的是网络错误还是权限不允许。 - 证书问题:验证:对比
~/.ssh/known_hosts中的主机名 ip地址是否与ping的结果一致,不一致则删除。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论