Git config

TIL

http

# 快速查看/校验 http 相关配置
git config --global --get-regexp '^http\.'
git config --system --get-regexp '^http\.'

# 强制使用 HTTP/1.1(部分代理/CDN 与 HTTP/2 不兼容时)
git config --global http.version HTTP/1.1

# 代理设置:支持 http/https/socks5/socks5h
git config --global http.proxy http://127.0.0.1:7890
# 代理优先级(高→低):http.<url>.proxy > http.proxy > 环境变量(HTTPS_PROXY/http_proxy/ALL_PROXY)

# 为 HTTPS 单独设代理(两种正确方式)
# 1) 环境变量(仅在未设置 http.proxy 时生效;仅影响 HTTPS)
#    临时:HTTPS_PROXY=http://127.0.0.1:7890 git clone https://...
#    全局:在 shell 配置里 export HTTPS_PROXY=http://127.0.0.1:7890
# 2) 按 URL 覆盖(推荐按站点定向;覆盖 http.proxy)
#    仅对 GitHub 使用此代理:
#    git config --global http.https://github.com/.proxy http://127.0.0.1:7890

# socks5/socks5h 核心区别:DNS 解析位置不同
# socks5:本机先把域名解析成 IP,再走代理。
# socks5h:让代理服务器解析域名(h=hostname),DNS 在代理端进行。
# 走 SOCKS5 且让代理解析域名(推荐)
git config --global http.proxy socks5h://127.0.0.1:7890

# 不走代理的域名/网段
# Git 没有 http.noProxy 配置;请用环境变量 NO_PROXY/no_proxy(逗号分隔)
# 临时:NO_PROXY="localhost,127.0.0.1,.local,*.corp" git fetch
# 全局:在 shell 配置里 export NO_PROXY="localhost,127.0.0.1,.local,*.corp"
# 也可对某域禁用代理(设置空值覆盖):
# git config --global http.https://intranet.corp/.proxy ""

# 低速/超时:网络不稳时可放宽,避免 push/pull 超时
git config --global http.lowSpeedLimit 0   # 0 表示禁用低速检测
git config --global http.lowSpeedTime 0    # 秒;0 表示禁用

# 自定义 User-Agent(个别网关基于 UA 做策略时)
# git config --global http.userAgent "git/2.x (custom)"

# 额外请求头(强烈建议按域名定向设置,避免泄露)
# 示例:为特定域名携带 Token
# git config --global http.https://example.com/.extraHeader "Authorization: Bearer <TOKEN>"
# 移除额外请求头
# git config --global --unset-all http.https://example.com/.extraHeader

# Cookies:需要与内网 SSO/网关维持会话时使用
# git config --global http.cookieFile ~/.gitcookies
# git config --global http.saveCookies true

# 按域名覆盖示例:仅对 github 强制 HTTP/1.1
# git config --global http.https://github.com/.version HTTP/1.1

pull

git config --global pull.rebase true