Informal Sharing with hg serve

Mercurial’s hg serve command is wonderfully suited to small, tight-knit, and fast-paced group environments. It also provides a great way to get a feel for using Mercurial commands over a network.

Run hg serve inside a repository, and in under a second it will bring up a specialized HTTP server; this will accept connections from any client, and serve up data for that repository until you terminate it. Anyone who knows the URL of the server you just started, and can talk to your computer over the network, can then use a web browser or Mercurial to read data from that repository. A URL for a hg serve instance running on a laptop is likely to look something like http://my-laptop.local:8000/.

The hg serve command is not a general-purpose web server. It can do only two things:

  • Allow people to browse the history of the repository it’s serving, from their normal web browsers.

  • Speak Mercurial’s wire protocol, so that people can hg clone or hg pull changes from that repository.

In particular, hg serve won’t allow remote users to modify your repository. It’s intended for read-only use.

If you’re getting started with Mercurial, there’s nothing to prevent you from using hg serve to serve up a repository on your own computer, then use commands like hg clone, hg incoming, and so on to talk to that server as if the repository were hosted remotely. This can help you to quickly get acquainted with using commands on network-hosted repositories.

A Few Things to Keep in Mind ...

Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.