查看“︁Git/代理”︁的源代码
来自康健生活
←
Git/代理
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 标题文本 == 查看代理信息 {{shc|<syntaxhighlight lang="bash"> git config --global -l</syntaxhighlight>|$|/home/kangkk}} == 全局代理 == {{shc|<syntaxhighlight lang="bash"> 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'</syntaxhighlight>|$|/home/kangkk}} 参考 {| class="wikitable" |- ! Git协议 !! 代理协议 !! 配置文件 !! 配置 |- | HTTP(s) || HTTP || <nowiki>~/.gitconfig</nowiki> || {{shc|<syntaxhighlight lang="bash"> git config --global http.proxy http://127.0.0.1:1080</syntaxhighlight>|$|/home/kangkk}} |- | HTTP(s) || SOCKS || <nowiki>~/.gitconfig</nowiki> || {{shc|<syntaxhighlight lang="bash"> git config --global http.proxy socks5h://127.0.0.1:1080</syntaxhighlight>|$|/home/kangkk}} |- | SSH || HTTP || <nowiki>~/.ssh/config</nowiki> || {{shc|<syntaxhighlight lang="bash"> Host github.com ProxyCommand nc -v -X connect -x 127.0.0.1:1080 %h %p</syntaxhighlight>|$|/home/kangkk}} |- | SSH || SOCKS || <nowiki>~/.ssh/config</nowiki> || {{shc|<syntaxhighlight lang="bash"> Host github.com ProxyCommand nc -v -X 5 -x 127.0.0.1:1080 %h %p</syntaxhighlight>|$|/home/kangkk}} |} 并且 ssh 代理还是要区分操作系统。 参考 https://zhuanlan.zhihu.com/p/481574024 === 取消代理 === {{shc|<syntaxhighlight lang="bash"> git config --global --unset http.proxy git config --global --unset https.proxy</syntaxhighlight>|$|/home/kangkk}} === 代理服务器鉴权 === {{shc|<syntaxhighlight lang="bash"> git config --global https.proxy https://username:password@proxy.abc.com:808 </syntaxhighlight>|$|/home/kangkk}} 需要注意的是账号密码信息用 Percent-encoding(百分号编码) 编码格式转换,以避免特殊符号如 @ 等干扰命令字符串解析<ref>https://stackoverflow.com/questions/6172719/escape-character-in-git-proxy-password</ref>。 == 分流 == 只对特定仓库进行代理 {{shc|<syntaxhighlight lang="bash"> 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</syntaxhighlight>|$|/home/kangkk}} 或者使用 socks {{shc|<syntaxhighlight lang="bash"> 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</syntaxhighlight>|$|/home/kangkk}} == 配置文件 == {{hc|head=~/.gitconfig|output=<syntaxhighlight lang="bash"> [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 </syntaxhighlight>}} {{shc|<syntaxhighlight lang="bash"> git config -l --global</syntaxhighlight>|$|/home/kangkk}} 可以通过域名使用 http.proxy 进行有条件的代理设置。例如: {{hc|head=~/.gitconfig|output=<syntaxhighlight lang="bash"> [http "https://example.com/"] http.proxy = socks5h://127.0.0.1:1080 </syntaxhighlight>}} {{shc|<syntaxhighlight lang="bash"> git config -l --global</syntaxhighlight>|$|/home/kangkk}} == ssh == ssh 代理,先查看 DNS 解析 {{Shc_out|<syntaxhighlight lang="bash"> nslookup github.com</syntaxhighlight>|<syntaxhighlight lang="text">服务器: unifi.localdomain Address: 192.168.51.1 非权威应答: 名称: github.com Address: 20.205.243.166 </syntaxhighlight>|$|/home/kangkk}} === windows === 测试联通 {{shc|<syntaxhighlight lang="bash"> ssh -T git@github.com</syntaxhighlight>|$|/home/kangkk}}
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
模板:Linenum
(
查看源代码
)
模板:Linenum/style.css
(
查看源代码
)
模板:Shc
(
查看源代码
)
模板:Shc/style.css
(
查看源代码
)
模板:Shc out
(
查看源代码
)
模板:Shc out/style.css
(
查看源代码
)
返回
Git/代理
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。