To proxy one HTTPS clone without changing the Python process's environment or writing a global Git setting, pass the variables to Repo.clone_from:

from git import Repo

repo = Repo.clone_from(
    'https://git.example/team/project.git',
    '/path/to/new-checkout',
    env={
        'http_proxy': 'http://proxy.example:8080',
        'https_proxy': 'http://proxy.example:8080',
    },
)

Use the proxy URL directly in the Python strings. For a public repository and a route where public proxies are allowed, the HTTP proxy list supplies candidate endpoints. Shell grouping quotes are not part of that URL. An SSH repository URL follows the SSH transport instead, so this example requires an HTTPS repository URL.

If Git still takes another route

The env mapping updates the environment inherited by the Git subprocess; it does not replace that environment with an empty one. Check inherited no_proxy values for a bypass, and check Git's own http.proxy configuration, which can override the corresponding environment setting.

You may also encounter examples passing config to the clone. That invokes Git clone's --config option and writes configuration into the new repository. Choose that only when the setting should outlive this clone process; clone-time versus invocation-only Git configuration explains the difference.

Mikanda mikatakata