Working with a Repository

In Mercurial, everything happens inside a repository. The repository for a project contains all of the files that belong to that project, along with a historical record of the project’s files.

There’s nothing particularly magical about a repository; it is simply a directory tree in your filesystem that Mercurial treats as special. You can rename or delete a repository any time you like, using either the command line or your file browser.

Making a Local Copy of a Repository

Copying a repository is just a little bit special. While you could use a normal file copying command to make a copy of a repository, it’s best to use a built-in command that Mercurial provides. This command is called hg clone, because it makes an identical copy of an existing repository.

$ hg clone http://hg.serpentine.com/tutorial/hello
destination directory: hello
requesting all changes
adding changesets
adding manifests
adding file changes
added 5 changesets with 5 changes to 2 files
updating working directory
2 files updated, 0 files merged, 0 files removed, 0 files unresolved

One advantage of using hg clone is that, as we can see above, it lets us clone repositories over the network. Another is that it remembers where we cloned from, which we’ll find useful soon when we want to fetch new changes from another repository.

If our clone succeeded, we should now have a local directory called hello. This directory will contain some files.

$ ls -l total 4 drwxrwxr-x 3 bos bos 4096 May 5 06:44 ...

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.