By Leo Lin, Product Manager at FlashIP (https://www.flaship.com/), Singapore.
Every few weeks someone sends me a message that starts with "the proxy works in my browser but not in the terminal." Nine times out of ten it's not the proxy. Git and npm each have their own proxy settings, they also read environment variables, and the two sources quietly fight each other. This is the checklist I use when setting up a laptop on a company network that forces outbound traffic through a proxy, or when a team wants CI jobs to fetch from a fixed egress IP that a partner has allow-listed.
First, decide where the setting should live
There are three places a proxy can come from:
- Environment variables (
http_proxy,https_proxy,no_proxy, and their uppercase versions). Many tools read them, which is convenient and also the reason leftovers cause chaos. - Git config (
~/.gitconfigor a repo's.git/config). - npm config (
~/.npmrcor a project.npmrc).
My rule: use environment variables on CI runners, where each job starts clean, and use tool-specific config on laptops, where you want predictable behaviour and an easy way to undo it.
Git over HTTPS
The basic setting is one line:
git config --global http.proxy http://proxy.example.com:8080 Git applies http.proxy to both http:// and https:// remotes. If you only need the proxy for one host, say an external GitHub mirror while internal servers stay direct, scope it to a URL instead:
git config --global http.https://github.com.proxy http://proxy.example.com:8080 About credentials. You can write http://user:pass@proxy.example.com:8080, but then your password sits in plain text in .gitconfig, which often ends up in dotfile repos. Git's documentation describes a better option: give a user name without a password (http://user@proxy.example.com:8080) and Git asks for the password through its normal credential system, so a credential helper can store it securely.
SOCKS5. Git hands proxy strings to libcurl, so socks5h://proxy.example.com:1080 works too. The h means the proxy resolves hostnames, which matters on networks where internal DNS can't see public hosts.
SSH remotes are different. If your remote looks like git@github.com:org/repo.git, http.proxy does nothing. Either switch that remote to HTTPS or configure a ProxyCommand in ~/.ssh/config. This one catches people constantly.
To undo:
git config --global --unset http.proxy npm
npm uses two separate keys, and forgetting the second one is the most common mistake I see:
npm config set proxy http://proxy.example.com:8080 npm config set https-proxy http://proxy.example.com:8080 The registry is HTTPS, so https-proxy is the one that actually matters for most installs. Note that the value is usually still an http:// URL; it describes how you talk to the proxy, not the destination.
If you run a private registry inside the network, keep it off the proxy:
npm config set noproxy "localhost,127.0.0.1,.internal.example.com" npm also honours HTTP_PROXY and HTTPS_PROXY from the environment, so if your .npmrc looks right but traffic still goes somewhere odd, check env | grep -i proxy first.
Corporate TLS inspection: don't turn off verification
Many company proxies decrypt and re-sign HTTPS traffic with an internal certificate authority. The symptom is SELF_SIGNED_CERT_IN_CHAIN in npm or SSL certificate problem in Git. The tempting fix, strict-ssl=false or http.sslVerify=false, disables protection for everything. Ask IT for the CA certificate and point the tools at it instead:
git config --global http.sslCAInfo /path/to/company-ca.pem npm config set cafile /path/to/company-ca.pem Check that it actually works
Don't trust the config file, trust a request:
# Git: verbose output shows the proxy connection GIT_CURL_VERBOSE=1 git ls-remote https://github.com/git/git 2>&1 | grep -i proxy # npm: show effective settings, then make one real request npm config list npm view lodash version If you're testing a fixed egress IP for an allow-list, also run curl https://api.ipify.org with the same environment variables and confirm the address is the one you gave your partner.
Quick troubleshooting
- 407 Proxy Authentication Required: wrong or missing credentials. Re-enter them, watch for special characters that need URL-encoding (
@becomes%40), and check your plan still has traffic or time left. - Works in Git, fails in npm: you set
proxybut nothttps-proxy. - Works in the terminal, fails in CI: the runner doesn't have your shell profile. Set the variables in the job definition.
- Internal hosts time out: add them to
no_proxy/noproxy. - Random behaviour after switching networks: remove stale settings with
git config --global --unset http.proxyandnpm config delete proxy/npm config delete https-proxy, then reapply only what you need.
Picking a proxy for this
For developer tooling, the checklist is short: the protocol your tools speak (HTTP(S) covers both Git and npm; SOCKS5 is a bonus for Git), the authentication you prefer, and whether you need a stable IP for allow-lists. FlashIP supports HTTP(S) and SOCKS5 with either username:password or IP whitelist authentication; details are on flaship.com. Whatever provider or corporate proxy you use, run the checks above before you blame the network.
Disclosure: I work on FlashIP.
## 