Configuring a proxy to work with Git
This article discusses configuring Git to work with different proxies. It is often difficult to access Git when working behind a corporate firewall.
We'll cover some of the proxies that Git supports, how to configure them, and how to provide the proxy to our command line for a one-time use. Let's jump right in.
Proxy protocols supported in Git
Git supports the following proxies:
- HTTP
- HTTPS
- SOCKS4
- SOCKS5
Using HTTP Proxy with Git Commands
We usually edit the Git configuration file to use a proxy. However, Git allows us to provide the proxy to the terminal for quick use.
This is an example of an HTTP proxy on the command line.
$ git config --global http.proxy http://username:password@proxy_server.com:port
In a scenario with a specific domain, we will run the command as shown below.
$ git config --global http.http://specific_domain.com.proxy http://username:password@proxy_server.com:port
Notice that we http.proxy
added our domain between and that we provided the full proxy URL. The full URL enables Git to automatically recognize and run the protocol.
Using HTTPS proxy with Git commands
In the scenario where we are working behind a firewall, following is how we will run the commands for the HTTPS proxy protocol.
$ git config --global http.https://specific_domain.com.proxy http://username:password@proxy_server.com:port
The URL is between http.proxy
, but note the change from http://specific_domain.com
to https://specific_domain.com
.
You can disable SSL verification to avoid problems as shown below.
$ git config --global http.https://specific_domain.com.sslVerify false
Permanently configure the proxy in the Git configuration file
We can store the above settings permanently in the Git configuration file. We use --global
the switch to set the configuration for all users and connections.
Use --Global
the switch to set the global proxy
If we need all Git operations to go through the proxy, we run:
$ git config --global http.proxy http://username:password@proxy_server.com:port
Setting up a proxy for a specific domain
If we want a specific domain to connect through our proxy, we would run the following command.
$ git config --global http.https://domain.com.proxy http://username:password@proxy_server.com:port
Disable HTTPS Authentication
If you receive this error message 无法访问 'https://...': Unknown SSL protocol error in connection to ...:443
, you can turn off SSL verification as shown below.
$ git -c http.sslVerify=false clone https://domain.com/example.git
Alternatively, you can disable it all together as shown below.
$ git config http.sslVerify false
Remove proxy settings for Git repository
We use the command below to list all the proxies connected to our repository.
$ git config --get-regexp http.*
We can use any of the following syntaxes to remove our proxy.
$ git config --unset http.proxy
$ git config --unset http.https://domain.com.proxy
or
$ git config --unset http.sslVerify
$ git config --unset http.https://domain.com.sslVerify
As shown below, we can add global
the switch to remove the proxy settings from all of our repositories.
$ git config --global --unset http.proxy
$ git config --global --unset http.https://domain.com.proxy
SOCKS
Configuring a proxy in Git
As mentioned earlier, Git supports the socks5://
and socks4://
protocols.
Run the following command to configure SOCKS
the protocol.
$ git config --global http.proxy socks5://proxy_server.com:port
For a specific domain, run:
$ git config --global http.https://domain.com.proxy socks5://proxy_server.com:port
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Git list remote branches
Publish Date:2025/04/20 Views:54 Category:OPERATING SYSTEM
-
This article will show you how to list remote repositories from your local branch. A remote repository is a project hosted on a server, such as Github/Gitlab. git remote Allows us to use short names (aliases) to execute commands instead of
Pushing from an existing remote repository to another remote repository in Git
Publish Date:2025/04/20 Views:67 Category:OPERATING SYSTEM
-
This tutorial will teach you how to push from an existing remote repository to a different remote repository in Git. Git is a version control system used to track changes in a project directory. Git uses commits for such purposes. In Git, y
Update the repository remotely by setting
Publish Date:2025/04/20 Views:120 Category:OPERATING SYSTEM
-
In this tutorial, we will discuss how to set up the central repository as a remote for our local repository so that our branch is updated whenever the central repository changes. We should always perform this step before making edits to our
Rename Git repository
Publish Date:2025/04/20 Views:100 Category:OPERATING SYSTEM
-
In this article, we will discuss renaming Git repositories. We can explain this in different ways. It can rename the displayed name, the repository on GitHub, or the folder of the repository. We will discuss these and go through the steps w
Creating tags in a Git repository
Publish Date:2025/04/20 Views:117 Category:OPERATING SYSTEM
-
In this tutorial, we will discuss how to create tags in a Git repository. Creating tags in a Git repository In Git, we may want to mark certain commits or specific points in the history of the project repository. To do this, we can use the
Push Git tags to remote repositories
Publish Date:2025/04/20 Views:177 Category:OPERATING SYSTEM
-
If you create a git tag locally, your intention must be to share your changes with your team for easy tracking. Commit is one of the common operations to share changes. But another sharing and tracking idea added to it is Git Tags. This art
Fixed: Git Is Not Recognized as an Internal or External Command error
Publish Date:2025/04/20 Views:198 Category:OPERATING SYSTEM
-
This article discusses three methods we can use to fix "git" Is Not Recognized as an Internal or External Command when using Git in the Windows Command Prompt . This is a frequently reported error by users who prefer running Git commands on
Ignore untracked files in Git
Publish Date:2025/04/20 Views:162 Category:OPERATING SYSTEM
-
This article will discuss two methods that can be used to ignore untracked files in a Git repository. If there are multiple untracked files and folders in your local repository, running the git status command will output many lines. Let’s
Ignore everything except certain files in Git
Publish Date:2025/04/20 Views:151 Category:OPERATING SYSTEM
-
This article outlines the steps to make Git ignore all but a few files in a Git repository. The .gitignore file is a useful Git utility that allows us to tell Git which files to track and which files not to track. If you want your .gitignor