hg-clone
Clone a Mercurial repository
TLDR
Clone a repository to a specified directory
Clone a repository to the head of a specific branch, ignoring later commits
Clone a repository with only the .hg directory, without checking out files
Clone a repository to a specific revision, tag or branch, keeping the entire history
Clone a repository up to a specific revision without any newer history
SYNOPSIS
hg clone [OPTION]... SOURCE [DEST]
PARAMETERS
SOURCE
Path or URL of the repository to clone.
DEST
Optional path for the new repository. If omitted, the last component of the SOURCE path/URL is used.
-r <REVISION>, --rev <REVISION>
Clone only up to the specified revision, limiting the history copied to the new repository.
-U, --noupdate
Do not update the working directory after cloning. Only the .hg repository data is created.
-u <UPDATE>, --updaterev <UPDATE>
Update the working directory to the specified revision after cloning.
--pull
Pull all changesets into the new repository but do not update the working directory. Similar to 'hg init' followed by 'hg pull'.
--uncompressed
Store cloned data uncompressed in the new repository. This can result in larger disk usage but may offer performance benefits in some scenarios.
--stream
Use the stream clone protocol if supported by the server. This can significantly speed up cloning of large repositories.
--insecure
Do not verify SSL certificates when connecting to HTTPS repositories. Use with extreme caution as it bypasses security checks.
-v, --verbose
Enable verbose output, showing more details about the cloning process.
-q, --quiet
Suppress output, making the command execute silently.
DESCRIPTION
The `hg clone` command creates a complete, independent copy of an existing Mercurial repository. This includes the entire history of the source repository, encompassing all changesets, branches, and tags. It is a fundamental operation in distributed version control workflows, enabling developers to obtain a local, working copy of a project to contribute to or work with independently. The newly cloned repository retains a link to its original source, facilitating subsequent `pull` and `push` operations to synchronize changes.
Cloning can be performed from various sources, including local file paths or remote URLs using protocols like HTTP, HTTPS, or SSH. By default, `hg clone` not only copies the repository data but also checks out the latest revision (tip of the default branch) into a working directory. This allows immediate interaction with the project files. Options are available to modify this behavior, such as cloning only the repository contents without updating the working directory, or specifying a particular revision to update to.
CAVEATS
Cloning large repositories can consume significant disk space and network bandwidth, potentially taking a long time.
The --insecure option should be used with extreme caution, as it disables crucial SSL certificate verification, making your connection vulnerable to man-in-the-middle attacks.
Using -r to clone a specific revision limits the history copied into the new repository; the new repository will not contain changesets beyond that revision. To get the full history but update the working directory to an older revision, use -u instead.
DEFAULT BEHAVIOR
By default, `hg clone` copies the entire history of the source repository and updates the working directory in the new repository to the tip (latest revision) of the default branch. This provides an immediately usable local copy of the project.
PROTOCOL SUPPORT
Mercurial's `clone` command supports various protocols for source repositories, including local file paths, `http://`, `https://`, `ssh://`, and `file://`. This flexibility allows cloning from diverse network locations and local file systems.
REPOSITORY HOOKS
Clone operations can trigger specific hooks. The source repository can execute a `pre-clone` hook before the cloning process begins, and the destination (newly created) repository can execute a `post-clone` hook after the cloning is complete. These allow for custom automation around cloning events.
HISTORY
The `clone` command has been a foundational element of Mercurial (hg) since its inception in 2005. Developed by Matt Mackall, Mercurial, much like Git, emerged from the need for an open-source distributed version control system. The `clone` operation was critical from day one to support Mercurial's distributed architecture, allowing developers to easily create local copies of repositories. While its core functionality has remained consistent, performance enhancements, such as the introduction of stream clones, and robust protocol handling have been integrated over time to improve its efficiency and reliability.