-
Notifications
You must be signed in to change notification settings - Fork 6
GitHub 项目用代理推送至服务器 #18
Copy link
Copy link
Closed
Labels
DeploymentDeploy content to serverDeploy content to serverServerThe invisible heroThe invisible hero
Description
需求描述
在本机编写的项目,时不时地就因为众所周知的原因无法推送到 GitHub 上了。既然阳关大道走不通,那就只好走独木桥了。
方案调研
调研过程
本机的项目往 GitHub 推送失败时,会报下面的错误:
ssh: connect to host github.com port 22: Connection timed out
用上面的报错信息 Google,看到 Stack Overflow 上有解决方法:git - ssh: connect to host github.com port 22: Connection timed out | Stack Overflow。
上面的修改只是让本机项目走 http 协议,还要让项目走本地代理才行,设置方式参考:laispace/git 设置和取消代理。
入选方案
- git - ssh: connect to host github.com port 22: Connection timed out | Stack Overflow:修改本机项目,用不同的协议推送到 GitHub。
- laispace/git 设置和取消代理:设置 git 使用本地 http 或 socks5 代理。
应用过程
在终端先用指令 ssh -T [email protected] 测试是否能通过 ssh 连接到 GitHub 上,如果提示连接超时,说明 ssh 的确连不到 GitHub 上。
ssh 不行,那就换 http 方式。在项目所在目录中,执行 git config --local -e,会显示当前项目的 git 设置,把 ssh 方式的 URL:url = [email protected]:username/repo.git 改成 http 方式的 URL:url = https://github.com/username/repo.git。
然后!不要忘了然后,还要让 git 走本地代理。当然了,http.proxy 和 https.proxy 后面究竟是用 socks5 还是 http,都要看代理软件的设置,根据自己的实际情况来就行。
$ git config --global https.proxy 'socks5://127.0.0.1:1080'
$ git config --global http.proxy 'socks5://127.0.0.1:1080'要点总结
Google + Stack Overflow 解决程序员所有问题 😄
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
DeploymentDeploy content to serverDeploy content to serverServerThe invisible heroThe invisible hero