Skip to content

Instantly share code, notes, and snippets.

@kiraio-moe
Last active November 28, 2022 19:44
Show Gist options
  • Save kiraio-moe/c02faf20abdab2874663c69cda5d923a to your computer and use it in GitHub Desktop.
Save kiraio-moe/c02faf20abdab2874663c69cda5d923a to your computer and use it in GitHub Desktop.
How to use git over proxy server?

πŸ“˜ Overview

There are many ways to use git with a proxy server, but for now I'll only explain how to use it using http/https and ssh protocols.
Let's see how to use git with a proxy!

βš™οΈ Configurations

πŸ›‘οΈ SSH

Basically it works with any other proxy tool, just adjust proxycommand attribute according to proxy tool you are using with.
In this case, I'm gonna using socat.

socat stands for SOcket CAT, it's a utility for data transfer between two addresses.

  • Install socat using your Distro's package manager.

  • Create or add the following line into ~/.ssh/config:

    host github.com
      hostname ssh.github.com
      port 443
      user git
      proxycommand socat - PROXY:<host>:%h:%p, proxyport=<port>
  • Replace <host> and <port> with your proxy settings.

  • If your proxy need authentication, add proxyauth=<username>:<password> after proxyport. Separated by comma ,.

    proxycommand socat - PROXY:<host>:%h:%p, proxyport=<port>, proxyauth=<username>:<password>
    

    πŸš€ Test Out

    git clone [email protected]:username/repo.git
    

πŸ” HTTP / πŸ”’ HTTPS

  • Add the following line into ~/.gitconfig:

    [http]
    [http "https://github.com"]
      proxy = http://<username>:<password>@<host>:<port>
      sslVerify = false
    
  • Replace <username>, <password>, <host> and <port> according to your proxy settings.

  • If your proxy doesn't need authentication, just remove the <username> and <password>.

    proxy = http://<hostname>:<port>

    πŸš€ Test Out

    git clone https://github.com/username/repo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment