Git代理:针对单一网站设置

958 阅读1分钟

解决方案来源于:git 设置和取消代理 (github.com)

设置代理

git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080

取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy

只对某网站使用代理

git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
#取消代理
git config --global --unset http.https://github.com.proxy

git代理配置位于~/.gitconfig,添加针对某网站使用的设置,全局设置就可以去掉了。

#推荐使用此方式
[http "https://github.com"]
 proxy = socks5://127.0.0.1:1080
  
#不建议使用全局处理
[http]
 proxy = http://127.0.0.1:1080
[https]
 proxy = http://127.0.0.1:1080

带认证的SSH代理

git config --global https.proxy https://[your_proxy_ip]:[your_proxy_port]

错误处理

  1. ssh: connect to host ssh.github.com port 22: Connection refused fatal: Could not read from remote repository.

解决方案:

win10配置:.ssh/config 配置文件供参考:

Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 22
ProxyCommand connect -S 127.0.0.1:7890 %h %p