Forked from coin8086/using-proxy-for-git-or-github.md
Created
January 12, 2023 05:56
-
-
Save cosmtrek/5222845a9b1ca5fc25fe8d2b51c5e340 to your computer and use it in GitHub Desktop.
Revisions
-
coin8086 revised this gist
Jun 9, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ # Use Proxy for Git/GitHub Generally, the Git proxy configuration depends on the [Git Server Protocol](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) you use. And there're two common protocols: SSH and HTTP/HTTPS. Both require a proxy setup already. In the following, I assume a SOCKS5 proxy set up on `localhost:1080`. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later. ## SSH Protocol When you do `git clone ssh://[user@]server/project.git` or `git clone [user@]server:project.git`, you're using the SSH protocol. You need to configurate your SSH client to use a proxy. Add the following to your SSH config file, say `~/.ssh/config`: ``` ProxyCommand nc -x localhost:1080 %h %p @@ -32,7 +32,7 @@ The above SSH configuration involves Linux command [`nc`](https://linux.die.net/ ## HTTP/HTTPS Protocol When you do `git clone http://example.com/gitproject.git` or `git clone https://example.com/gitproject.git`, you're using the HTTP/HTTPS protocol. Git respects `http_proxy` and `https_proxy` envrionment variables, so you can simply execute the following command in a shell: @@ -69,7 +69,7 @@ Execute this command under a shell with `user` and `host` replaced with yours. T ## A Little More on Git Protocol By saying "Git Protocol", I mean a [Git Server Protocol](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) called "The Git Protocol". It has a URI like `git://server/project.git`. Note it starts with a `git://`, not `ssh://` or `http://` or something else. It's not commonly used, so you can skip this. I write this mainly for completeness of Git proxy settings. -
coin8086 revised this gist
Sep 23, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export http_proxy=socks5://localhost:1080 https_proxy=socks5://localhost:1080 After that, your git command under the same shell will use the proxy *for HTTP/HTTPS connections*. BTW, Git also has a `http.proxy` configuration to override those two envrionment variables: ``` http.proxy @@ -69,7 +69,7 @@ Execute this command under a shell with `user` and `host` replaced with yours. T ## A Little More on Git Protocol By saying "Git Protocol", I mean a [Git Server Protocal](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) called "The Git Protocol". It has a URI like `git://server/project.git`. Note it starts with a `git://`, not `ssh://` or `http://` or something else. It's not commonly used, so you can skip this. I write this mainly for completeness of Git proxy settings. -
coin8086 revised this gist
Jul 2, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -69,7 +69,7 @@ Execute this command under a shell with `user` and `host` replaced with yours. T ## A Little More on Git Protocol By saying "Git Protocol", I mean a [Git Server Protocal](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) called "The Git Protocol". Its URI likes `git://server/project.git`. Note it starts with a `git://`, not `ssh://` or `http://` or something else. It's not commonly used, so you can skip this. I write this mainly for completeness of Git proxy settings. -
coin8086 revised this gist
Jul 2, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ If you want to use a HTTP proxy at `localhost:1080`, do it like: ProxyCommand nc -X connect -x localhost:1080 %h %p ``` You may want to use a proxy for a specific host, say GitHub. You can do it like this: ``` Host github.com -
coin8086 revised this gist
Jul 2, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Use Proxy for Git/GitHub Generally, the Git proxy configuration depends on the [Git Server Protocal](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) you use. And there're two common protocals: SSH and HTTP/HTTPS. Both require a proxy setup already. In the following, I assume a SOCKS5 proxy set up on `localhost:1080`. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later. ## SSH Protocol -
coin8086 revised this gist
Aug 11, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,7 +55,7 @@ does for other credentials. See gitcredentials(7) for more information. The synt This can be overridden on a per-remote basis; see remote.<name>.proxy ``` You can set the `http.proxy` configuration by `git config` command(or by editing the git config file directly) instead of export those environment variables. ## Setup a SOCKS5 Proxy -
coin8086 revised this gist
Aug 11, 2018 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,6 +55,8 @@ does for other credentials. See gitcredentials(7) for more information. The synt This can be overridden on a per-remote basis; see remote.<name>.proxy ``` You can set the `http.proxy` configuration with `git config` command(or edit the git config file) instead of export those environment variables. ## Setup a SOCKS5 Proxy It's very easy to setup a SOCKS5 proxy with your SSH Client: @@ -86,6 +88,8 @@ Can be overridden by the GIT_PROXY_COMMAND environment variable (which always ap without the special "for" handling). ``` You can set it by `git config`. ## Other Refereneces * http://cms-sw.github.io/tutorial-proxy.html -
coin8086 revised this gist
Aug 11, 2018 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -84,4 +84,9 @@ match wins. Can be overridden by the GIT_PROXY_COMMAND environment variable (which always applies universally, without the special "for" handling). ``` ## Other Refereneces * http://cms-sw.github.io/tutorial-proxy.html * https://github.com/cms-sw/cms-git-tools/blob/master/git-proxy -
coin8086 revised this gist
Aug 11, 2018 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,10 +77,11 @@ Git a has configration `core.gitProxy` dedicated for this protocol, its man read core.gitProxy A "proxy command" to execute (as command host port) instead of establishing direct connection to the remote server when using the Git protocol for fetching. If the variable value is in the "COMMAND for DOMAIN" format, the command is applied only on hostnames ending with the specified domain string. This variable may be set multiple times and is matched in the given order; the first match wins. Can be overridden by the GIT_PROXY_COMMAND environment variable (which always applies universally, without the special "for" handling). ``` -
coin8086 revised this gist
Aug 11, 2018 . 1 changed file with 24 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ # Use Proxy for Git/GitHub Generally, the Git proxy configuration depends on the [Git Server Protocal](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) you use. And there're two common protocals: SSH and HTTP/HTTPS. Both requires a proxy setup already. In the following, I assume a SOCKS5 proxy set up on `localhost:1080`. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later. ## SSH Protocol When you do `git clone ssh://[user@]server/project.git` or `git clone [user@]server:project.git`, you're using the SSH protocal. You need to configurate your SSH client to use a proxy. Add the following to your SSH config file, say `~/.ssh/config`: ``` ProxyCommand nc -x localhost:1080 %h %p @@ -28,7 +28,7 @@ Host github.com This uses a proxy only for GitHub, so that when you `git clone [email protected]:your-name/your-project.git`, the proxy works. The above SSH configuration involves Linux command [`nc`](https://linux.die.net/man/1/nc) and [ssh config](https://linux.die.net/man/5/ssh_config) `ProxyCommand`. Learm more about them if you're interested. ## HTTP/HTTPS Protocol @@ -42,7 +42,7 @@ export http_proxy=socks5://localhost:1080 https_proxy=socks5://localhost:1080 After that, your git command under the same shell will use the proxy *for HTTP/HTTPS connections*. BTW, Git also has a `http.proxy` configuration to override these two envrionment variables: ``` http.proxy @@ -65,3 +65,22 @@ ssh -ND 1080 user@host Execute this command under a shell with `user` and `host` replaced with yours. This is to setup a SOCKS5 proxy at port `1080` at localhost. ## A Little More on Git Protocol By say "Git Protocol", I mean a [Git Server Protocal](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) called "The Git Protocol". Its URI likes `git://server/project.git`. Note it starts with a `git://`, not `ssh://` or `http://` or something else. It's not commonly used, so you can skip this. I write this mainly for completeness of Git proxy settings. Git a has configration `core.gitProxy` dedicated for this protocol, its man reads: ``` core.gitProxy A "proxy command" to execute (as command host port) instead of establishing direct connection to the remote server when using the Git protocol for fetching. If the variable value is in the "COMMAND for DOMAIN" format, the command is applied only on hostnames ending with the specified domain string. This variable may be set multiple times and is matched in the given order; the first match wins. Can be overridden by the GIT_PROXY_COMMAND environment variable (which always applies universally, without the special "for" handling). ``` -
coin8086 revised this gist
Aug 11, 2018 . 1 changed file with 16 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Using Proxy for Git/GitHub Generally, the Git proxy config depends on the [Git Protocal](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) you use. And there're two common protocals: SSH and HTTP/HTTPS. Both requires a proxy setup already. In the following, I assume a SOCKS5 proxy set up on `localhost:1080`. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later. ## SSH Protocol @@ -10,7 +10,9 @@ When you do `git clone ssh://[user@]server/project.git` or `git clone [user@]ser ProxyCommand nc -x localhost:1080 %h %p ``` This is to make all SSH connections, including those by Git, via the proxy at `localhost:1080`. If you want to use a HTTP proxy at `localhost:1080`, do it like: ``` ProxyCommand nc -X connect -x localhost:1080 %h %p @@ -35,7 +37,7 @@ When you do `git clone http://example.com/gitproject.git` or `git clone https:// Git respects `http_proxy` and `https_proxy` envrionment variables, so you can simply execute the following command in a shell: ``` export http_proxy=socks5://localhost:1080 https_proxy=socks5://localhost:1080 ``` After that, your git command under the same shell will use the proxy *for HTTP/HTTPS connections*. @@ -52,3 +54,14 @@ does for other credentials. See gitcredentials(7) for more information. The synt [protocol://][user[:password]@]proxyhost[:port]. This can be overridden on a per-remote basis; see remote.<name>.proxy ``` ## Setup a SOCKS5 Proxy It's very easy to setup a SOCKS5 proxy with your SSH Client: ``` ssh -ND 1080 user@host ``` Execute this command under a shell with `user` and `host` replaced with yours. This is to setup a SOCKS5 proxy at port `1080` at localhost. -
coin8086 revised this gist
Aug 11, 2018 . 1 changed file with 23 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,47 +1,54 @@ # Using Proxy for Git/GitHub Generally, the Git proxy config depends on the [Git Protocal](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) you use. And there're two common protocals: SSH and HTTP/HTTPS. Both requires a proxy setup already. In the following, I assume a SOCKS5 proxy is set up on `localhost:1080`. But it can also be a HTTP proxy. ## SSH Protocol When you do `git clone ssh://[user@]server/project.git` or `git clone [user@]server:project.git`, you're using the SSH protocal. You need to config your SSH client to use a proxy. Add the following to your SSH config file, say `~/.ssh/config`: ``` ProxyCommand nc -x localhost:1080 %h %p ``` This is to make all SSH connections, including those by Git, via the proxy at `localhost:1080`. If you want to use a HTTP proxy, do it like: ``` ProxyCommand nc -X connect -x localhost:1080 %h %p ``` You may want to use a proxy only for specific host, say GitHub. You can do it like this: ``` Host github.com User git ProxyCommand nc -x localhost:1080 %h %p ``` This uses a proxy only for GitHub, so that when you `git clone [email protected]:your-name/your-project.git`, the proxy works. The above SSH config involves Linux command [`nc`](https://linux.die.net/man/1/nc) and [ssh config](https://linux.die.net/man/5/ssh_config) `ProxyCommand`. Learm more about them if you're interested. ## HTTP/HTTPS Protocol When you do `git clone http://example.com/gitproject.git` or `git clone https://example.com/gitproject.git`, you're using the HTTP/HTTPS protocal. Git respects `http_proxy` and `https_proxy` envrionment variables, so you can simply execute the following command in a shell: ``` export http_proxy=socks5://127.0.0.1:1080 https_proxy=socks5://127.0.0.1:1080 ``` After that, your git command under the same shell will use the proxy *for HTTP/HTTPS connections*. BTW, Git also has a `http.proxy` config to override these two envrionment variables: ``` http.proxy Override the HTTP proxy, normally configured using the http_proxy, https_proxy, and all_proxy environment variables(see curl(1)). In addition to the syntax understood by curl, it is possible to specify a proxy string with a user name but no password, in which case git will attempt to acquire one in the same way it does for other credentials. See gitcredentials(7) for more information. The syntax thus is [protocol://][user[:password]@]proxyhost[:port]. This can be overridden on a per-remote basis; see remote.<name>.proxy ``` -
coin8086 revised this gist
Aug 11, 2018 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,5 +39,9 @@ BTW, Git also has a `http.proxy` config to override these two envrionment variab ``` http.proxy Override the HTTP proxy, normally configured using the http_proxy, https_proxy, and all_proxy environment variables (see curl(1)). In addition to the syntax understood by curl, it is possible to specify a proxy string with a user name but no password, in which case git will attempt to acquire one in the same way it does for other credentials. See gitcredentials(7) for more information. The syntax thus is [protocol://][user[:password]@]proxyhost[:port]. This can be overridden on a per-remote basis; see remote.<name>.proxy ``` -
coin8086 created this gist
Aug 11, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ # Using Proxy for Git/GitHub Generally, the Git proxy config depends on the [Git Protocal](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) you use. And there're two common protocals: SSH and HTTP/HTTPS. Both requires a proxy setup already. In the following, I assume a SOCKS5 proxy is set up on `localhost:1080`. ## SSH When you do `git clone ssh://[user@]server/project.git` or `git clone [user@]server:project.git`, you're using the SSH protocal. You need to config the SSH. Add this to your SSH config file, say `~/.ssh/config`: ``` ProxyCommand nc -x localhost:1080 %h %p ``` This is to make all SSH connections, including those by Git, via the proxy. Probably you want more control on proxying only specific host, say GitHub. You can do it like this: ``` Host github.com User git ProxyCommand nc -x localhost:1080 %h %p ``` This works for GitHub repo accessed by SSH, like `git clone [email protected]:coin8086/vimrc.git`. The SSH config involves Linux command [`nc`](https://linux.die.net/man/1/nc) and [ssh config](https://linux.die.net/man/5/ssh_config) `ProxyCommand`. ## HTTP/HTTPS When you do `git clone http://example.com/gitproject.git` or `git clone https://example.com/gitproject.git`, you're using the HTTP/HTTPS protocal. Git respects `http_proxy` and `https_proxy` envrionment variables, so you can simply execute the following command in the shell: ``` export http_proxy=socks5://127.0.0.1:1080 https_proxy=socks5://127.0.0.1:1080 ``` BTW, Git also has a `http.proxy` config to override these two envrionment variables: ``` http.proxy Override the HTTP proxy, normally configured using the http_proxy, https_proxy, and all_proxy environment variables (see curl(1)). In addition to the syntax understood by curl, it is possible to specify a proxy string with a user name but no password, in which case git will attempt to acquire one in the same way it does for other credentials. See gitcredentials(7) for more information. The syntax thus is [protocol://][user[:password]@]proxyhost[:port]. This can be overridden on a per-remote basis; see remote.<name>.proxy ```