Git 代理配置

发布时间: 更新时间: 总字数:424 阅读时间:1m 作者: IP属地: 分享 复制网址

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:// 协议的代理需要配置 sshProxyCommand 参数

  • 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/configProxyCommand

全局代理

# socks5 协议
git config --global http.proxy socks5://127.0.0.1:1081
git config --global https.proxy socks5://127.0.0.1:1081

# http 协议
git config --global https.proxy http://127.0.0.1:8001
git config --global https.proxy https://127.0.0.1:8001

取消代理:

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

github 代理

# socks5 协议
git config --global http.https://github.com.proxy socks5://127.0.0.1:1081
git config --global https.https://github.com.proxy socks5://127.0.0.1:1081

# http 协议
git config --global http.https://github.com.proxy https://127.0.0.1:8001
git config --global https.https://github.com.proxy https://127.0.0.1:8001

取消代理:

git config -l
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

镜像站点替代

git config --global url."https://hub.fastgit.xyz/".insteadOf "https://github.com/"

git config --global --unset url.https://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/"
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数