# git代理设置（Configure Git to use a proxy）




- 通过命令行设置

  ```shell
  # 以clash代理工具为例

  # 全局设置代理
  git config --global http.proxy http://127.0.0.1:7890

  # 格式：git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port

  # 为特定网站设置代理（例如：github）
  git config --global http.https://github.com.proxy http://127.0.0.1:7890

  # 列出当前以http开头的配置

  # 获取全局配置
  git config --global --get-regexp http.*
  # 获取当前仓库配置
  git config --get-regexp http.*

  # 取消git代理
  # 全局
  git config --global --unset http.proxy
  # 特定网站（例如：github）
  git config --global --unset http.https://github.com.proxy
  ```

  ​

- 通过修改配置信息设置

  有空在写.....



&gt;参考文章如下，原文地址：[gist.github.com](https://gist.github.com/evantoli/f8c23a37eb3558ab8765)



## In Brief

You may need to configure a proxy server if you&#39;re having trouble cloning or fetching from a remote repository or getting an error like `unable to access &#39;...&#39; Couldn&#39;t resolve host &#39;...&#39;`.

Consider something like:

```
git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
```

Or for a specific domain, something like:

```
git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
git config --global http.https://domain.com.sslVerify false
```

Setting `http.&lt;url&gt;.sslVerify` to `false` may help you quickly get going if your workplace employs man-in-the-middle HTTPS proxying. Longer term, you could get the root CA that they are applying to the certificate chain and specify it with either `http.sslCAInfo` or `http.sslCAPath`.

See also the [git-config](https://git-scm.com/docs/git-config) documentation, especially the following sections if you&#39;re having HTTPS/SSL issues

- `http.sslVerify`
- `http.sslCAInfo`
- `http.sslCAPath`
- `http.sslCert`
- `http.sslKey`
- `http.sslCertPasswordProtected`

## In Detail

### Configure the proxy

You can configure these globally in your user `~/.gitconfig` file using the `--global` switch, or local to a repository in its `.git/config` file.

#### Setting a global proxy

Configure a global proxy if all access to all repos require this proxy

```
git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
```

#### URL specific proxy

If you wish to specify that a proxy should be used for just some URLs that specify the URL as a git config subsection using `http.&lt;url&gt;.key` notation:

```
git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
```

Which will result in the following in the `~/.gitconfig` file:

```
[http]
[http &#34;https://domain.com&#34;]
	proxy = http://proxyUsername:proxyPassword@proxy.server.com:port
```

#### Handle subsequent SSL protocol errors

If you&#39;re still having trouble cloning or fetching and are now getting an `unable to access &#39;https://...&#39;: Unknown SSL protocol error in connection to ...:443` then you may decide to switch off SSL verification for the single operation by using the `-c http.sslVerify=false` option

```
git -c http.sslVerify=false clone https://domain.com/path/to/git
```

Once cloned, you may decide set this for just this cloned repository&#39;s `.git/config` by doing. Notice the absence of the `--global`

```
git config http.sslVerify false
```

If you choose to make it global then limit it to a URL using the `http.&lt;url&gt;.sslVerify` notation:

```
git config --global http.https://domain.com.sslVerify false
```

Which will result in the following in the `~/.gitconfig` file:

```
[http]
[http &#34;https://domain.com&#34;]
	proxy = http://proxyUsername:proxyPassword@proxy.server.com:port
	sslVerify = false
```

### Show current configuration

To show the current configuration of all `http` sections

```
git config --global --get-regexp http.*
```

If you are in a locally cloned repository folder then you drop the `--global` and see all current config:

```
git config --get-regexp http.*
```

### Unset a proxy or SSL verification

Use the `--unset` flag to remove configuration being specific about the property -- for example whether it was `http.proxy` or `http.&lt;url&gt;.proxy`. Consider using any of the following:

```
git config --global --unset http.proxy
git config --global --unset http.https://domain.com.proxy

git config --global --unset http.sslVerify
git config --global --unset http.https://domain.com.sslVerify
```


---

> 作者: hiifong  
> URL: https://f.style/git.proxy/  

