当前位置:首页 > PHP教程 > PHP总结归纳

通过代理使用GitHub

git 是非常好用的开发工具,越来越离不开了。 如果要与他人合作项目,github 是很好的平台。 但如果身处受限网络,要管理 github 上的项目, 还是要费一番周折的。 github 网页访问应该不用说了,工具多得是。 我要说的是对项目进行管理,比如 push/pull 操

git 是非常好用的开发工具,越来越离不开了。 如果要与他人合作项目,github 是很好的平台。 但如果身处受限网络,要管理 github 上的项目, 还是要费一番周折的。

github 网页访问应该不用说了,工具多得是。 我要说的是对项目进行管理,比如 push/pull 操作等。

最简单的方式是通过 https_proxy,比如:

export https_proxy=http://127.0.0.1:8087

然后将仓库地址改为 http 方式。

虽然简单,但有一点不方便,就是进行写操作时, 比如 push ,会需要手工输入用户名和密码, 而不是 github 常用的证书自动认证。

更好的方法还是走 ssh 协议代理, 这需要一个软件 connect-proxy。 ubuntu 下可以通过 apt 安装, archlinux 下要通过 aur 安装( 包地址 )。

先要有 socks 代理,通常,可以使用无限制网络的 vps, 然后使用 ssh 打个隧道:

# native ssh ssh -d 127.0.0.1:22888 -cfng domain.tld -o controlpath=/tmp/ssh-22888-domain.tld # or # 使用 authssh 更方便 autossh -m 0 -d 127.0.0.1:22888 -cfng domain.tld -o controlpath=/tmp/ssh-22888-domain.tld

可以 telnet localhost 22888 检查通不通。

然后,在 $home/.ssh/config 中添加一段:

host github.com # on ubuntu proxycommand /usr/bin/connect-proxy -s 127.0.0.1:22888 %h %p # or # on archlinux proxycommand /usr/bin/connect -s 127.0.0.1:22888 %h %p

-s 参数如果换成 -h ,就是使用 http 代理, 效果应该和上面的简单方法一样。

最后,将仓库地址改为 ssh 方式。 现在,本地 github 仓库中 push 操作就正常了,简单测试一下 github 登录:

$ ssh -t git@github.com hi fwolf! you've successfully authenticated, but github does not provide shell access.

参考

  • how to set up git to get through a proxy
  • git pull/push to github.com in proxy environment
  • 如何为 git 设置代理?
  • github 使用socks 代理



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!