Skip to content

http-backend Git Command Guide

The git http-backend command is a CGI program that serves Git repository content over HTTP and HTTPS protocols, enabling web-based Git hosting and remote access.

  • Smart HTTP Protocol: Supports efficient Git transfer over HTTP
  • Backward Compatibility: Fallback to dumb HTTP for older clients
  • Security Control: Repository access verification via file markers
  • Protocol Support: Handles fetch, push, and repository discovery
<VirtualHost *:80>
ServerName git.example.com
DocumentRoot /var/www/git
ScriptAlias / /usr/lib/git-core/git-http-backend/
<Directory "/usr/lib/git-core">
Options ExecCGI
AllowOverride None
Require all granted
</Directory>
Alias /static /usr/share/gitweb/static
<Directory "/usr/share/gitweb/static">
AllowOverride None
Require all granted
</Directory>
</Directory>
Terminal window
# Mark repository for export
touch /path/to/repo.git/git-daemon-export-ok
# Or export all repos (less secure)
export GIT_HTTP_EXPORT_ALL=1
AuthType Basic
AuthName "Git Access"
AuthUserFile /etc/git-users
Require valid-user
MethodDescription
GIT_HTTP_EXPORT_ALLExport all accessible repositories
git-daemon-export-okMark specific repositories for export
Web Server AuthHTTP authentication for access control
HTTPS RequiredSSL/TLS encryption for security
  • No anonymous access to sensitive repositories
  • Requires web server configuration and permissions
  • File system permissions must allow web server access
Terminal window
curl -u user:password https://git.example.com/repo.git/info/refs

Test authenticated repository access via HTTP.

Terminal window
git push https://user@git.example.com/repo.git master

Push commits using smart HTTP protocol for efficiency.

Terminal window
git clone https://git.example.com/repo.git

Clone repository using HTTP backend serving.

Terminal window
GET https://git.example.com/repo.git/HEAD

Verify web server correctly routes to git-http-backend CGI.

Terminal window
curl -I https://git.example.com/large-repo.git/info/refs

Check headers for large repository HTTP serving capability.

How do I configure Apache for git-http-backend?

Section titled “How do I configure Apache for git-http-backend?”

Set up ScriptAlias to point to git-http-backend binary, configure CGI execution permissions, and set up authentication as needed.

What’s the difference between smart and dumb HTTP?

Section titled “What’s the difference between smart and dumb HTTP?”

Smart HTTP uses efficient binary transfer protocols like Git’s native protocol. Dumb HTTP downloads repository files individually, much slower for large repos.

Can git-http-backend serve read-only repositories?

Section titled “Can git-http-backend serve read-only repositories?”

Yes, by default only upload-pack (read/fetch) service is enabled. Add authentication to enable receive-pack (push) service.

How does authentication work with git-http-backend?

Section titled “How does authentication work with git-http-backend?”

Authentication is handled by the web server (Apache/Nginx), not Git. Git receives authenticated user context for hook execution.

What’s required for push operations over HTTP?

Section titled “What’s required for push operations over HTTP?”

receive-pack service must be enabled (requires authentication) and repository must be writable by web server user.

Git LFS works over HTTP backends same as other Git operations - LFS pointers are handled by client, not server.

How do I troubleshoot git-http-backend issues?

Section titled “How do I troubleshoot git-http-backend issues?”

Check CGI execution permissions, repository access rights, web server logs, and git-http-backend direct command execution.

What’s the performance impact of HTTP vs SSH?

Section titled “What’s the performance impact of HTTP vs SSH?”

HTTP can be slower due to protocol overhead but provides better firewall traversal. Performance depends on server configuration and network.

  1. Web Hosting: Serve Git repositories through web servers like Apache/Nginx
  2. Firewall Friendly: Access repositories over HTTP/S when SSH is blocked
  3. CDN Compatible: Potential for HTTP caching and CDN acceleration of Git operations
  4. Browser Access: Enable web-based Git repository browsing and cloning
  5. Enterprise Deployment: Large-scale Git repository hosting in corporate environments
  6. Cloud Integration: Support Git operations in cloud web application platforms