hg-serve
Serve Mercurial repositories over HTTP
TLDR
Start a web server instance
Start a web server instance on the specified port
Start a web server instance on the specified listening address
Start a web server instance with a specific identifier
Start a web server instance using the specified theme (see the templates directory)
Start a web server instance using the specified SSL certificate bundle
SYNOPSIS
hg serve [options]
PARAMETERS
-6, --ipv6
use IPv6 instead of IPv4
-A, --accesslog FILE
access log file location
-p, --port PORT
port to listen on (default: 8000)
-n, --name NAME
hostname to use in canonical URL (default: localhost)
--certificate CERT
SSL certificate file path
--daemon
run server in background
--errorlog FILE
error log file location
--pid-file FILE
file to store process ID
--prefix PREFIX
URL prefix for repository
--print-url
print the served repository URL
--stdio
use stdin/stdout for requests (CGI)
--templates PATH
directory for web templates
--web-conf FILE
web server configuration file
--web-dir DIR
root directory for repositories
--web-name NAME
name for the web interface
DESCRIPTION
The hg serve command starts a built-in HTTP server that exposes the current Mercurial repository for sharing with other users. It allows clients to clone, pull, and push changesets via HTTP without needing a dedicated web server like Apache. Ideal for quick sharing during development or ad-hoc collaboration.
By default, it listens on port 8000 and serves from the current directory as the repository root. The server supports basic authentication if configured in .hg/hgrc, and can be customized with templates, access logs, and virtual hosting. It handles multiple repositories under --web-dir and supports subrepositories with --subrepos.
Use cases include temporary team shares, code reviews, or serving as a poor man's CI. However, it's not production-ready due to lack of HTTPS by default, limited scalability, and potential security risks from unauthenticated access. Run with --daemon for background operation or --stdio for CGI-like integration.
CAVEATS
Not suitable for production due to unencrypted HTTP by default, no rate limiting, and single-threaded operation. Exposes repository publicly unless firewalled or password-protected. Use hg serve --web-conf for auth.
SECURITY NOTE
Always configure [web] permissions in .hg/hgrc to restrict push/pull access.
Use --certificate for HTTPS.
STOPPING THE SERVER
Interrupt with Ctrl+C or kill the PID from --pid-file. No graceful shutdown option.
HISTORY
Introduced in Mercurial 0.9b (2006) by Matt Mackall as a simple sharing tool. Evolved with SSL support in 1.0 (2008) and subrepo handling in later versions. Remains lightweight alternative to hgweb.cgi.


