Please enable Javascript to view the contents

GIT-配置proxy并忽略内网仓库

 ·  ☕ 1 分钟

重要

实现的状态

  • github仓库走代理
  • 内网仓库不走代理

1.简介

由于github仓库拉取缓慢,所以配置了代理; 但内网仓库拉取也走了代理,导致出现以下报错

1
2
hex@hex-pc:~/example-repo$ git pull 
fatal: unable to access 'https://git.service.rd/plugins/git/example-repo.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.

解决办法(推荐)

git是可以根据环境变量的配置,声明代理并将内网地址配置不走代理,实现此功能,但要注意格式。

1
2
3
4
5
6
7
export https_proxy=http://127.0.0.1:10800/
export http_proxy=http://127.0.0.1:10800/
export all_proxy=socks://127.0.0.1:1088/
export ftp_proxy=http://127.0.0.1:10800

# 声明内网不走proxy的服务 声明域名作为通配,以空格分隔。
export no_proxy=".service.rd .icos.city 127.0.0.1 localhost"

修改本地库-local配置

也可以针对仓库设置git config。可以设置本地库全局配置,也可以只设置单一远端。

  1. 已有仓库,进入仓库目录下,并添加一个“空”代理(仓库级别)。
1
git config --local --add http.proxy ""

在仓库目录下<repo_path>/.git/config,会出现以下内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = https://git.service.rd/plugins/git/example.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[http]
	proxy = 
  1. 已有仓库,进入仓库目录下,添加一个”空“代理(固定remote级别)。
1
git config --local --add remote.<name>.proxy ""

执行下面命令查看

1
git config --local --get remote.<name>.proxy

修改全局配置(只能针对单库)

修改 ~/.gitconfig文件,增加以下内容

1
2
3
4
5
[http]
   sslVerify = true
[http "https://git.service.rd/plugins/git/example-repo.git"]
   sslVerify = false
   ptoxy = 
分享

Hex
作者
Hex
CloudNative Developer

目录