Git with Proxy

1. Problem Description

When you enable a proxy, you can visit GitHub but your git operation like git push failed. Some info reminds you:

1
2
3
4
5
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

This means, you enabled the proxy, but the git, didn’t connect network with proxy.

2. How to Solve

To solve the problem, we need configure the git:

Assume your proxy software’s port is 7897.

Enable Git’s proxy:

1
2
git config --global http.proxy http://127.0.0.1:7897
git config --global https.proxy http://127.0.0.1:7897

[!NOTE]

Here, the https.proxy also connect to the http port provided by proxy software.

You can check the proxy states:

1
2
git config --global --get http.proxy
git config --global --get https.proxy

Operate Git Commands like git push

[!NOTE]

If your proxy isn’t always enabled, you may should disable the git proxy after the system proxy disabled.

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

本文链接:https://wangyier.top/git-with-proxy/

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 The Great Library