﻿---
title: Set Git Proxy
date: 2025-05-30
excerpt: Set up a proxy for Git operations, both for HTTP/HTTPS and SSH connections.
tags:
  - OS
  - Git
  - SSH
cover: https://assets.vluv.space/cover/ToolChain/git_proxy.webp
updated: 2026-07-08 07:21:51
lang: en
i18n:
  cn: /git_proxy
  translation: 2
---

## Git Proxy

### HTTP & HTTPS

When your proxy tool provides an HTTP proxy service on port 7890, you can add the following configuration to `~/.gitconfig` so Git's HTTP and HTTPS requests go through the proxy.

```gitconfig
[https]
    proxy = http://127.0.0.1:7890
[http]
    proxy = http://127.0.0.1:7890
```

If you only want GitHub traffic to use the proxy, add the following configuration to `~/.gitconfig`.

```gitconfig
[http "https://github.com"]
    proxy = http://127.0.0.1:7890
[https "https://github.com"]
    proxy = http://127.0.0.1:7890
```

### SSH

Edit `~/.ssh/config` and add a `ProxyCommand` entry to route SSH through the proxy.

> [!WARN] Proxy Port
>
> SSH proxies usually need a **SOCKS5 port** and cannot be forwarded through a regular HTTP proxy port.
>
> Because I enabled the mixed port in Clash Verge Rev, the `ProxyCommand` here still uses `127.0.0.1:7890`; it supports both HTTP and SOCKS5. See [Proxy Port - Void Terminal Docs](https://wiki.metacubex.one/config/inbound/port/) for the related explanation.

#### Windows Example

Git for Windows includes `connect.exe`, which can be used for proxy forwarding. I installed Git with Scoop, so my `connect.exe` path is `D:\envir_vars\scoop\apps\git\current\mingw64\bin\connect.exe`. Adjust it to match your actual path.

```ssh-config
Host github.com
  User git
  Hostname ssh.github.com
  Port 443
  IdentityFile "~/.ssh/id_rsa"
  TCPKeepAlive yes
  ProxyCommand "D:\envir_vars\scoop\apps\git\current\mingw64\bin\connect.exe" -S 127.0.0.1:7890 %h %p // [!code ++]
```

#### Mac Example

On macOS, you can use the system-provided `nc` for proxy forwarding.

```ssh-config
Host github.com
  User git
  Hostname ssh.github.com
  Port 443
  IdentityFile "~/.ssh/id_rsa"
  TCPKeepAlive yes
  ProxyCommand nc -X 5 -x 127.0.0.1:7890 %h %p // [!code ++]
```
