Tutorial - Cloning a Repository
(This page is part of the Tutorial series. Previous part is TutorialInit, next part is TutorialHistory)
You have followed TutorialInstall to install Mercurial already, right? Good!
In Mercurial, we do all of our work inside a repository. A repository is a directory that contains all of the source files that we want to keep history of, along with complete histories of those source files (inside the .hg directory — see UnderstandingMercurial).
The easiest way to get started with Mercurial is to use a repository that already contains some files and some history.
To do this, we use the clone command.1 This makes a clone of a repository; it makes a complete copy of another repository so that we will have our own local, private one to work in.
Let's clone a small "hello, world" repository hosted at selenic.com:
$ hg clone http://www.selenic.com/repo/hello my-hello
If all goes well, the clone command prints this (Mercurial 1.4):
requesting all changes adding changesets adding manifests adding file changes added 2 changesets with 2 changes to 2 files updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
We should now find a directory called my-hello in our current directory:
$ ls my-hello
Inside the my-hello directory, we should find some files, together with the .hg directory, that contains Mercurial's private data (basically the history of the repository plus various state information — see Repository for more information):
$ ls -a . .. .hg Makefile hello.c
These files are exact copies of the files from the tip revision of the default branch in the repository we just cloned.
Note: in Mercurial, each repository is self-contained. When you clone a repository, the new repository becomes an exact copy of the existing one at the time of the clone, but subsequent changes in either one will not show up in the other unless you explicitly transfer them, by either pulling or pushing.
By default, hg clone checks out (see update) the latest revision (usually referred to as the tip) of the repository's default branch into the repository's working directory. To see which revision is currently checked out, we can use the summary command:2
$ cd my-hello $ hg summary parent: 1:82e55d328c8c tip Create a makefile branch: default commit: (clean) update: (current)
At this point, we can start examining some of the history of our new repository, by continuing to TutorialHistory.