Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git 代理配置 #46

Open
lihongxun945 opened this issue Jan 28, 2020 · 0 comments
Open

git 代理配置 #46

lihongxun945 opened this issue Jan 28, 2020 · 0 comments

Comments

@lihongxun945
Copy link
Owner

lihongxun945 commented Jan 28, 2020

国内使用github因为某些原因是比较慢的,如果没有配置代理基本都是 10KB/s 以内的速度,如果大家本地有科学上网的工具,那么可以通过配置让 git clone 的时候也走代理,这样速度会有质的飞跃。

git 可以配置使用 http 或者 socks5 都行,因为我们公司内网有gitlab,为了不影响避免内网也走代理导致无法同步代码,需要指定只有 github 才走代理,建议大家都这样配置而不是直接配置一个全局代理,配置如下(SOCKS/HTTP任选一种即可):

# socks5
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
# http
git config --global http.https://github.com.proxy https://127.0.0.1:1087
git config --global https.https://github.com.proxy https://127.0.0.1:1087

如果你本地服务只有http,那么地址需要改成 http://127.0.0.1:{端口号}

不过要注意,这仅对 HTTPS 协议的地址生效,如果你是用 SSH的协议,那么是不生效的,可以换成HTTPS 协议的下载地址,也可以通过配置让 SSH 都走 HTTPS 协议,这样就没问题了:

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://

经过测试,未代理之前是 10KB/S 左右,本地代理可以达到 6MB/s 的平均速度:

怎么删除上述配置内?其实git全局配置都在 ~/.gitconfig 文件中,直接进去删掉就好了。

参考:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant