http-fetch Git Command Guide
The git http-fetch protocol implements client-side HTTP fetching for retrieving Git objects and references from remote repositories served over HTTP/HTTPS.
HTTP Fetch Protocol Features:
Section titled “HTTP Fetch Protocol Features:”- Reference Discovery: Retrieve remote repository references via HTTP
- Efficient Transfer: Use smart HTTP protocol for optimized object fetching
- Authentication Support: Handle HTTP authentication and TLS certificates
- Incremental Updates: Support for shallow cloning and partial fetching
- Protocol Negotiation: Compatible with Git’s smart HTTPBackend servers
Protocol Components:
Section titled “Protocol Components:”Discovery Phase:
Section titled “Discovery Phase:”GET /repo.git/info/refs?service=git-upload-pack # Smart protocolGET /repo.git/HEAD # Default branchGET /repo.git/info/refs # Reference listingPack Transfer:
Section titled “Pack Transfer:”POST /repo.git/git-upload-pack # Upload pack negotiation# Binary pack data transfer follows acknowledgmentConfiguration Options:
Section titled “Configuration Options:”Authentication Setup:
Section titled “Authentication Setup:”git config credential.helper storegit config http.sslVerify truegit config http.postBuffer 524288000 # 500MB for large transfersProxy Configuration:
Section titled “Proxy Configuration:”git config http.proxy http://proxy.example.com:8080git config https.proxy https://secure-proxy.example.com:8080SSL/TLS Configuration:
Section titled “SSL/TLS Configuration:”git config http.sslCAInfo /path/to/ca-bundle.crtgit config http.sslCAPath /etc/ssl/certs/git config http.sslCert /path/to/client-cert.pemTroubleshooting Common Issues:
Section titled “Troubleshooting Common Issues:”Authentication Problems:
Section titled “Authentication Problems:”# Check stored credentialsgit config --list | grep credential
# Manual credential entrygit credential fill << EOFprotocol=httpshost=github.comEOFSSL Certificate Issues:
Section titled “SSL Certificate Issues:”# Disable SSL verification (not recommended)git config http.sslVerify false
# Add custom CA certificategit config http.sslCAInfo /path/to/ca-cert.pemgit http-fetch Command Samples:
Section titled “git http-fetch Command Samples:”Basic repository clone via HTTP
Section titled “Basic repository clone via HTTP”git clone https://github.com/user/repo.gitStandard clone operation using HTTP fetch protocol.
Fetch updates from remote
Section titled “Fetch updates from remote”git fetch originRetrieve latest changes using HTTP protocol.
Shallow clone for large repos
Section titled “Shallow clone for large repos”git clone --depth 1 https://github.com/user/repo.gitLimit history for faster initial fetch.
Clone with authentication
Section titled “Clone with authentication”git clone https://username@github.com/user/repo.gitFetch repository with username in URL.
Fetch specific branch
Section titled “Fetch specific branch”git fetch origin feature-branch:local-branchRetrieve specific remote branch to local.
Update with custom buffer size
Section titled “Update with custom buffer size”GIT_HTTP_BUFFER=524288000 git fetch originIncrease buffer size for large repository fetches.
Fetch with proxy configuration
Section titled “Fetch with proxy configuration”git -c http.proxy=http://proxy.example.com:8080 fetch originFetch through HTTP proxy server.
Troubleshooting failed fetch
Section titled “Troubleshooting failed fetch”GIT_CURL_VERBOSE=1 git fetch origin 2>&1 | head -50Enable verbose HTTP debugging output.
How does HTTP transfer differ from SSH?
Section titled “How does HTTP transfer differ from SSH?”HTTP uses regular web ports (80/443) while SSH uses port 22. HTTP can cache at network level but typically slower due to protocol overhead.
Why would HTTP fetch fail while SSH succeeds?
Section titled “Why would HTTP fetch fail while SSH succeeds?”Common causes: corporate proxies blocking Git protocol, authentication token expiry, SSL certificate trust issues, or server-side rate limiting.
What’s smart HTTP protocol?
Section titled “What’s smart HTTP protocol?”Optimized Git transfer over HTTP that uses Git’s native pack protocol instead of downloading individual files. Significantly faster than dumb HTTP.
How do I handle self-signed certificates?
Section titled “How do I handle self-signed certificates?”Use git config http.sslCAInfo to specify custom CA certificate, or disable verification with http.sslVerify false (not recommended for production).
Can I resume interrupted HTTP fetches?
Section titled “Can I resume interrupted HTTP fetches?”Partial pack file downloads cannot be resumed. Use git fetch —force to restart. For large repositories, consider shallow clones first.
What’s the impact of proxy on fetch performance?
Section titled “What’s the impact of proxy on fetch performance?”Proxies add latency and may cache stale responses. HTTP caching works poorly for Git’s dynamic fetch requests. SSH typically faster through proxies.
How do I debug HTTP connection issues?
Section titled “How do I debug HTTP connection issues?”Set GIT_CURL_VERBOSE=1 for detailed connection logs, check firewall/proxy policies, verify SSL certificates, and test direct HTTP access to repository.
Applications of the http-fetch command
Section titled “Applications of the http-fetch command”- Firewall Traversal: Access repositories through corporate firewalls that block SSH
- Public Repository Access: Standard method for cloning public Git repositories
- CDN Compatibility: Leverage web infrastructure for distributed repository serving
- Enterprise Environments: HTTP access through proxy servers and authenticated tunnels
- Continuous Integration: Automated fetching in CI/CD pipelines behind corporate networks
- Bandwidth Optimization: Smart HTTP’s efficient pack-based transfer for large repositories