Git/代理:修订间差异

来自康健生活
< Git
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第85行: 第85行:
{{shc|<syntaxhighlight lang="bash">
{{shc|<syntaxhighlight lang="bash">
git config -l --global</syntaxhighlight>|$|/home/kangkk}}
git config -l --global</syntaxhighlight>|$|/home/kangkk}}
== ssh ==
ssh 代理
=== windows ===

2025年7月17日 (四) 12:11的版本

标题文本

查看代理信息

/home/kangkk
git config --global -l

全局代理

/home/kangkk
git config --global http.proxy http://192.168.51.34:808
git config --global https.proxy https://192.168.51.34:808
git config --global http.proxy 'socks5://192.168.51.34:808'
git config --global https.proxy 'socks5://192.168.51.34:808'

参考

Git协议 代理协议 配置文件 配置
HTTP(s) HTTP ~/.gitconfig
/home/kangkk
git config --global http.proxy http://127.0.0.1:1080
HTTP(s) SOCKS ~/.gitconfig
/home/kangkk
git config --global http.proxy socks5h://127.0.0.1:1080
SSH HTTP ~/.ssh/config
/home/kangkk
Host github.com
  ProxyCommand nc -v -X connect -x 127.0.0.1:1080 %h %p
SSH SOCKS ~/.ssh/config
/home/kangkk
Host github.com
  ProxyCommand nc -v -X 5 -x 127.0.0.1:1080 %h %p

并且 ssh 代理还是要区分操作系统。

参考 https://zhuanlan.zhihu.com/p/481574024

取消代理

/home/kangkk
git config --global --unset http.proxy
git config --global --unset https.proxy

代理服务器鉴权

/home/kangkk
git config --global https.proxy https://username:password@proxy.abc.com:808

需要注意的是账号密码信息用 Percent-encoding(百分号编码) 编码格式转换,以避免特殊符号如 @ 等干扰命令字符串解析[1]。

分流

只对特定仓库进行代理

/home/kangkk
git config --global http.https://github.com.proxy http://192.168.51.34:808
git config --global https.https://github.com.proxy http://192.168.51.34:808

或者使用 socks

/home/kangkk
git config --global http.https://github.com.proxy socks5://192.168.51.34:1080
git config --global https.https://github.com.proxy socks5://192.168.51.34:1080

配置文件

~/.gitconfig
[http]
proxy = socks5://192.168.51.34:1080
proxy = http://192.168.51.34:1080

[https]
proxy = socks5://192.168.51.34:1080
proxy = https://192.168.51.34:1080
/home/kangkk
git config -l --global

可以通过域名使用 http.proxy 进行有条件的代理设置。例如:

~/.gitconfig
[http "https://example.com/"]
http.proxy = socks5h://127.0.0.1:1080
/home/kangkk
git config -l --global

ssh

ssh 代理

windows