LinuxCommandLibrary

hg-clone

Clone a Mercurial repository

TLDR

Clone a repository to a specified directory

$ hg clone [remote_repository_source] [destination_path]
copy

Clone a repository to the head of a specific branch, ignoring later commits
$ hg clone [[-b|--branch]] [branch] [remote_repository_source]
copy

Clone a repository with only the .hg directory, without checking out files
$ hg clone [[-U|--noupdate]] [remote_repository_source]
copy

Clone a repository to a specific revision, tag, or branch, keeping the entire history
$ hg clone [[-u|--updaterev]] [revision] [remote_repository_source]
copy

Clone a repository up to a specific revision without any newer history
$ hg clone [[-r|--rev]] [revision] [remote_repository_source]
copy

SYNOPSIS

hg clone [OPTION]... <SOURCE> [<DEST>]

PARAMETERS

-U, --noupdate
    do not update new working directories to tip revision

--pull
    use pull protocol (for SSH/HTTP, allows resuming)

--uncompressed
    use uncompressed transfer (faster on LAN)

-r REV, --rev REV
    clone up to specified revision only

-b BRANCH, --branch BRANCH
    clone only specified branch

--shallow BRANCHES
    create shallow clone excluding specified branches (Mercurial 5.0+)

--insecure
    do not verify HTTPS server certificate

-e CMD, --ssh CMD
    SSH command to use for cloning

--remotecmd CMD
    remote hg command to use (with --ssh)

DESCRIPTION

hg clone creates a complete, independent copy of a Mercurial repository, including its full revision history, tags, and branches.

This command is fundamental for version control workflows: developers use it to obtain a local copy from a remote server (e.g., Bitbucket, self-hosted), duplicate local repositories for testing, or set up new projects from templates.

Unlike shallow clones in Git, Mercurial clones fetch the entire history by default, ensuring offline access to all changes. The new repository is a peer to the source—no dependency exists post-clone.

By default, hg clone SOURCE DEST creates DEST (or SOURCE basename if omitted) and updates its working directory to the tip revision. Network clones use HTTP/HTTPS, SSH, or static HTTP intelligently. Large repositories benefit from options like --pull for resumability or --uncompressed for speed on fast links.

Clones support bookmarks and are safe for concurrent operations. Post-clone, use hg pull to sync changes.

CAVEATS

Cloning very large repositories over slow networks can take hours and fail midway (use --pull to resume).
Full clones consume significant disk space; consider --rev or --shallow for subsets.
Requires Mercurial installed and network access for remote sources.

EXAMPLES

hg clone https://hg.example.com/myrepo (clones to myrepo)
hg clone -U ssh://user@host/repo /local/path (no working dir update)
hg clone --rev 1.0 repo newcopy (up to tag 1.0)

PROTOCOLS

Supports http/https, ssh, local paths, bundle files. Prefers bundle2 for modern transfers.

HISTORY

Introduced in Mercurial 0.9b (2006); core since 0.1 (2005). Evolved with bundle2 protocol (3.2, 2015) for efficiency and shallow clones (5.0, 2019).

SEE ALSO

hg(1), git-clone(1), bzr(1)

Copied to clipboard