解决Github克隆源码龟速问题

本文目前仅讨论Windows环境下的git代理
目前github支持ssh及https两种传输协议。
  • ssh
    ssh的代理相对步骤相对比较繁琐一些,需要用到socat这个软件,下载后解压缩,并将解压缩目录加入PATH。
    之后,编写脚本文件,命名为gitproxy
#这里是代理ip及端口号
_proxy=127.0.0.1
_proxyport=1080
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport

保存后,将该脚本文件加入PATH。
添加git 配置,支持ssh代理

#脚本文件加入PATH
git config --global core.gitproxy 'gitproxy'
#脚本文件未加入PATH(需要改为你本地的脚本文件路径)
git config --global core.gitproxy 'C:\developers\config\gitproxy\connect-1.104-win32-msvc\gitproxy'

添加ssh支持

#在c:/user/{username}/.ssh/config文件夹内添加如下
# 此行要改路径 代理ip 及port
ProxyCommand connect.exe -H 127.0.0.1:1080 %h %p

Host github.com
User git
Port 22
Hostname github.com

#此行要改路径及id_dsa 或id_rsa
IdentityFile "C:\Users\Administrator\.ssh\id_rsa"

TCPKeepAlive yes
IdentitiesOnly yes

Host ssh.github.com
User git
Port 443
Hostname ssh.github.com

#此行要改路径及id_dsa 或id_rsa
IdentityFile "C:\Users\Administrator\.ssh\id_rsa"

TCPKeepAlive yes
IdentitiesOnly yes

至此,就实现了git://(ssh)协议的代理。

  • https
    https代理比较简单,只需直接配置git即可
#本地ss使用sockets代理,如使用http隧道则改为http://127.0.0.1:1080
git config --global https.proxy 'socks5://127.0.0.1:1080'
#一并配置http.proxy
git config --global http.proxy 'socks5://127.0.0.1:1080'

即完成https的代理。

linux环境暂未配置及测试,可以查看参考2.

参考:

  1. 在windows上通过代理访问github.com
  2. 如何为Git设置代理

你可能感兴趣的:(解决Github克隆源码龟速问题)