Git 在很多场景下存在网络问题,本文介绍如何为 git 客户端配置代理
git 代理
已知代理(如V*ray)默认端口:
- socks5 1081
- http 8001
http_proxy 方式
https_proxy=http://127.0.0.1:8001 git clone https://<git_url>gitproxy 方式
Git 目前支持的三种协议 git://、ssh:// 和 http://,其代理配置各不相同:
core.gitproxy用于git://协议http.proxy用于http://协议ssh://协议的代理需要配置ssh的ProxyCommand参数GIT 协议的配置
建立 /path/to/socks5proxywrapper 文件,使用 https://bitbucket.org/gotoh/connect 工具进行代理的转换,各发行版一般打包为 proxy-connect 或者 connect-proxy。
#!/bin/sh
nc -x 127.0.0.1:1081 "$@"配置 git
[core]
gitproxy = /path/to/socks5proxywrapper或者
export GIT_PROXY_COMMAND="/path/to/socks5proxywrapper"- SSH 协议的配置
建立 /path/to/soks5proxyssh 文件
#!/bin/sh
ssh -o ProxyCommand="/path/to/socks5proxywrapper %h %p" "$@"配置 git 使用该 wrapper
export GIT_SSH="/path/to/soks5proxyssh“当然也可以直接配置 ~/.ssh/config 的 ProxyCommand
全局代理
Git 的 HTTP/HTTPS 传输均使用 http.proxy 配置项(Git 没有 https.proxy 键):
# socks5 协议
git config --global http.proxy socks5://127.0.0.1:1081
# http 协议
git config --global http.proxy http://127.0.0.1:8001取消代理:
git config -l
git config --global --unset http.proxygithub 代理
针对指定域名(如 github.com)单独配置代理,语法为 http.<url>.proxy:
# socks5 协议
git config --global http.https://github.com.proxy socks5://127.0.0.1:1081
# http 协议
git config --global http.https://github.com.proxy http://127.0.0.1:8001取消代理:
git config -l
git config --global --unset http.https://github.com.proxy镜像站点替代
# 配置镜像加速(注:insteadOf 会同时改写 push 地址,推送前需 unset 还原)
git config --global url."https://gitclone.com/github.com/".insteadOf "https://github.com/"
# 取消镜像替代配置
git config --global --unset url."https://gitclone.com/github.com/".insteadOf# Replace git:// with https://
git config --global url."https://github".insteadOf git://github
# ssh instead of https://
git config --global url."git@github.com:".insteadOf "https://github.com/"最近更新
最新评论