Git error fatal unable to connect a socket Invalid argument
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The Git error fatal: unable to connect a socket (Invalid argument) appears when Git cannot establish a network connection to the remote repository. This typically points to a problem with your proxy configuration, the remote URL, or your system's network settings rather than a bug in Git itself. This article walks through the most common causes and provides step-by-step fixes.
What the Error Means
When Git performs network operations like clone, fetch, push, or pull, it opens a TCP socket to communicate with the remote server. The "Invalid argument" part means the operating system rejected the socket creation or connection request because one of the parameters passed to the system call was malformed or invalid.
The most frequent trigger is a misconfigured HTTP or HTTPS proxy. Git passes the proxy address to the system's socket layer, and if the proxy URL is malformed, the socket call fails with this error.
Checking Your Git Configuration
Start by inspecting your Git configuration for proxy settings and remote URLs.
Look for any proxy entries that contain typos, incorrect port numbers, or invalid characters.
Fix 1: Remove or Correct Proxy Settings
If you see a proxy configured and you are not behind a proxy, remove it:
If you are behind a corporate proxy, make sure the URL is correctly formatted:
Common mistakes in proxy URLs include forgetting the http:// prefix, using the wrong port, or including special characters in the password without URL-encoding them. If your proxy password contains characters like @, #, or %, URL-encode them:
Fix 2: Check the Remote URL
A malformed remote URL can also trigger this error. Verify and correct the remote URL:
Watch for these URL issues:
- Extra spaces or invisible characters copied from a web page
- Missing
.gitsuffix (though most hosting services handle this) - Using
http://when the server requireshttps:// - Incorrect hostname or path
Fix 3: Check System-Level Proxy Environment Variables
Git also respects system-level proxy environment variables. These can override or conflict with Git's own proxy settings.
If these are set incorrectly, unset them for your session or fix them in your shell profile:
On macOS, the system proxy settings in System Preferences (Network > Advanced > Proxies) can also affect Git. If you recently changed networks (for example, from a corporate office to home), the old proxy settings may still be active.
Fix 4: Test Network Connectivity
Verify that you can reach the remote server at all:
If curl and nslookup fail, the problem is your network connection or DNS, not Git.
Fix 5: IPv6 vs IPv4 Issues
On some systems, Git attempts an IPv6 connection first. If your network does not support IPv6 properly, the socket call can fail with "Invalid argument."
A more permanent fix is to prefer IPv4 in your SSH config if you use SSH remotes:
Fix 6: Update Git and Network Libraries
Outdated versions of Git or its dependencies (libcurl, OpenSSL) can have bugs related to socket handling.
If you are running Git version 2.20 or older, upgrading often resolves network-related errors that were fixed in later releases.
Common Pitfalls
- Checking only
git config --globaland missing repository-level settings. Rungit config --list --show-originto see all sources, including local.git/configand system-level/etc/gitconfig. - Setting the proxy in Git config but also having conflicting
http_proxyandHTTP_PROXYenvironment variables. Git checks both, and a mismatch can cause confusion. - Forgetting to URL-encode special characters in proxy passwords. Characters like
@,:, and#have special meaning in URLs and must be percent-encoded. - Switching between VPN, corporate network, and home network without updating proxy settings. Consider using conditional Git config includes based on the repository path to apply proxy settings only for work repos.
- Assuming the error is a Git bug when it is almost always a configuration or network issue.
Summary
The fatal: unable to connect a socket (Invalid argument) error is almost always caused by a misconfigured proxy, a malformed remote URL, or a network connectivity issue. Start by checking git config --list --show-origin for proxy settings, verify the remote URL with git remote -v, and test basic network connectivity with curl or ssh. Remove or correct any proxy settings that are no longer needed, and make sure environment variables like http_proxy are consistent with your Git configuration.
Related reading
- git fatal I don't handle protocol 'http
- Git fatal protocol 'https' is not supported
- git push fails RPC failed; result22, HTTP code 411
- git returns http error 407 from proxy after CONNECT
- Git error Host Key Verification Failed when connecting to remote repository
- Git error on commit after merge - fatal cannot do a partial commit during a merge
- Git error on git pull unable to update local ref
- Git error Please make sure you have the correct access rights and the repository exists

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.