git
error
socket
troubleshooting
connection issues

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.

Practice system design

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.

bash
1# Show all Git config values, including where each is set
2git config --list --show-origin
3
4# Check proxy settings specifically
5git config --global http.proxy
6git config --global https.proxy
7
8# Check the remote URL for your repository
9git remote -v

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:

bash
1# Remove global HTTP proxy
2git config --global --unset http.proxy
3
4# Remove global HTTPS proxy
5git config --global --unset https.proxy

If you are behind a corporate proxy, make sure the URL is correctly formatted:

bash
1# Correct format for HTTP proxy
2git config --global http.proxy http://proxy.company.com:8080
3
4# Correct format for authenticated proxy
5git config --global http.proxy http://username:[email protected]:8080
6
7# For SOCKS5 proxy
8git config --global http.proxy socks5://proxy.company.com:1080

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:

bash
# Password "p@ss#word" becomes "p%40ss%23word"
git config --global http.proxy http://user:p%40ss%[email protected]:8080

Fix 2: Check the Remote URL

A malformed remote URL can also trigger this error. Verify and correct the remote URL:

bash
1# View current remote URL
2git remote -v
3
4# Fix an HTTPS remote URL
5git remote set-url origin https://github.com/username/repo.git
6
7# Fix an SSH remote URL
8git remote set-url origin [email protected]:username/repo.git

Watch for these URL issues:

  • Extra spaces or invisible characters copied from a web page
  • Missing .git suffix (though most hosting services handle this)
  • Using http:// when the server requires https://
  • 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.

bash
1# Check environment variables
2echo $http_proxy
3echo $https_proxy
4echo $HTTP_PROXY
5echo $HTTPS_PROXY
6echo $no_proxy

If these are set incorrectly, unset them for your session or fix them in your shell profile:

bash
1# Unset for the current session
2unset http_proxy
3unset https_proxy
4unset HTTP_PROXY
5unset HTTPS_PROXY
6
7# Or bypass the proxy for specific hosts
8export no_proxy="github.com,gitlab.com,bitbucket.org"

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:

bash
1# Test HTTPS connectivity
2curl -v https://github.com
3
4# Test SSH connectivity
5ssh -T [email protected]
6
7# Test DNS resolution
8nslookup github.com
9
10# Test the specific port
11nc -zv github.com 443

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."

bash
1# Force Git to use IPv4
2git config --global http.version HTTP/1.1
3
4# Or force IPv4 at the system level for the current session
5export GIT_CURL_RESOLVE="github.com:443:140.82.121.3"

A more permanent fix is to prefer IPv4 in your SSH config if you use SSH remotes:

 
# ~/.ssh/config
Host github.com
    AddressFamily inet

Fix 6: Update Git and Network Libraries

Outdated versions of Git or its dependencies (libcurl, OpenSSL) can have bugs related to socket handling.

bash
1# Check Git version
2git --version
3
4# Update on macOS
5brew upgrade git
6
7# Update on Ubuntu/Debian
8sudo apt update && sudo apt upgrade git
9
10# Update on RHEL/CentOS
11sudo yum update git

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 --global and missing repository-level settings. Run git config --list --show-origin to see all sources, including local .git/config and system-level /etc/gitconfig.
  • Setting the proxy in Git config but also having conflicting http_proxy and HTTP_PROXY environment 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.