Git operations fail when the connection to the remote repository times out. This typically occurs during clone, fetch, push, or pull operations when the client cannot establish or maintain a connection to the Git server within the allocated time.
This error occurs when Git fails to complete a network operation within the expected timeframe. The timeout can happen at different stages: during the initial TCP connection, during the SSH handshake, or while transferring data. Common scenarios include SSH connections timing out on port 22, HTTPS operations exceeding the configured timeout limit, or large repository operations that take too long to complete. The error manifests differently depending on the protocol: SSH connections typically show "Operation timed out" or "Connection timed out", while HTTPS operations may display "Failed to connect" or "unable to access" messages. The underlying cause is usually network-related, such as firewall restrictions, proxy configurations, or actual network connectivity issues. Git has default timeout values that can be too short for slow connections or large repositories. Additionally, many corporate and public networks block specific ports (especially SSH port 22) or throttle Git traffic, leading to timeout errors even when the server is functioning normally.
First, verify the Git server is operational and your network is working:
# Check if the server is reachable
ping github.com
# Check GitHub status page
# Visit: https://status.github.com/
# Test basic SSH connectivity
ssh -T [email protected]
# For GitLab
ssh -T [email protected]If ping works but SSH fails, the issue is likely port or protocol-specific. If ping fails, check your internet connection or DNS settings.
Run Git commands with verbose flags to see where the timeout occurs:
# For SSH connections
GIT_SSH_COMMAND="ssh -v" git fetch
# For HTTPS connections
GIT_CURL_VERBOSE=1 git fetch
# Enable packet-level tracing
GIT_TRACE_PACKET=1 git clone <repo-url>This output will show exactly where the connection is failing, helping you determine if it's during connection, authentication, or data transfer.
Many firewalls block SSH port 22 but allow port 443 (HTTPS). Configure SSH to use port 443:
# Test if SSH over port 443 works
ssh -T -p 443 [email protected]
# If successful, add to ~/.ssh/config
cat >> ~/.ssh/config << 'EOF'
Host github.com
Hostname ssh.github.com
Port 443
User git
Host gitlab.com
Hostname altssh.gitlab.com
Port 443
User git
EOF
# Test the configuration
ssh -T [email protected]This allows SSH connections to work through firewalls that only permit standard web ports.
If SSH continues to fail, switch your remote URL to HTTPS:
# Check current remote URL
git remote -v
# Change to HTTPS (GitHub example)
git remote set-url origin https://github.com/username/repo.git
# For GitLab
git remote set-url origin https://gitlab.com/username/repo.git
# Verify the change
git remote -vHTTPS is more permissive on restricted networks but may require credential management.
Incorrect proxy configuration can cause timeouts:
# Check current proxy settings
git config --global --get http.proxy
git config --global --get https.proxy
# Clear proxy settings if misconfigured
git config --global --unset http.proxy
git config --global --unset https.proxy
# If you need a proxy, set it correctly
git config --global http.proxy http://proxy.company.com:8080
git config --global https.proxy http://proxy.company.com:8080Also check system environment variables: echo $HTTP_PROXY $HTTPS_PROXY
For large repositories, increase Git's timeout values:
# Increase HTTP post buffer (helps with large pushes)
git config --global http.postBuffer 524288000 # 500MB
# Increase low speed timeout (seconds Git waits if speed drops)
git config --global http.lowSpeedLimit 1000
git config --global http.lowSpeedTime 600 # 10 minutes
# Use shallow clone for initial checkout
git clone --depth 1 <repo-url>
# Later fetch full history if needed
git fetch --unshallowThese settings give Git more time to complete operations on slow or large transfers.
Network-specific restrictions are common:
# Disconnect from VPN and retry
# Or connect to VPN if previously disconnected
# Switch from WiFi to mobile hotspot
# This helps identify if the issue is network-specific
# Try using Cloudflare DNS (1.1.1.1) or Google DNS (8.8.8.8)
# This can resolve DNS timeout issuesIf operations succeed on a different network, the issue is with your original network's firewall or routing.
SSH Keep-Alive Configuration
To prevent SSH sessions from timing out during long operations, configure keep-alive:
# Add to ~/.ssh/config
Host *
ServerAliveInterval 60
ServerAliveCountMax 10This sends a keep-alive packet every 60 seconds, maintaining the connection during data transfer.
Network Diagnostics
For persistent issues, use network diagnostic tools:
# Trace route to identify where packets are blocked
traceroute github.com
# Advanced MTR diagnostics
mtr -T -P 22 github.com
# Check for packet loss
ping -c 100 github.com | grep lossGit Protocol Selection
Avoid the legacy git:// protocol (port 9418), which is unauthenticated and often blocked. Always use HTTPS or SSH instead.
Corporate Network Considerations
Many corporate networks use SSL inspection, which can interfere with Git operations. If you control the network, consider whitelisting Git hosting domains (github.com, gitlab.com, bitbucket.org) to bypass inspection.
Repository Size Optimization
For repositories with large binary files, consider using Git LFS (Large File Storage) to reduce clone and fetch times, which can prevent timeout issues.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git