#cargo #subcommand #clone

bin+lib cargo-clone

A cargo subcommand to fetch the source code of a Rust crate

8 releases (2 stable)

Uses new Rust 2021

1.0.1 Apr 27, 2022
1.0.0 Dec 26, 2021
0.2.0 Dec 25, 2021
0.1.4 Jan 27, 2020
0.1.0 Apr 16, 2016

#114 in Cargo plugins

Download history 72/week @ 2022-03-10 51/week @ 2022-03-17 99/week @ 2022-03-24 145/week @ 2022-03-31 179/week @ 2022-04-07 72/week @ 2022-04-14 192/week @ 2022-04-21 119/week @ 2022-04-28 109/week @ 2022-05-05 219/week @ 2022-05-12 89/week @ 2022-05-19 245/week @ 2022-05-26 117/week @ 2022-06-02 84/week @ 2022-06-09 81/week @ 2022-06-16 76/week @ 2022-06-23

380 downloads per month
Used in 3 crates (2 directly)


377 lines


cargo-clone can be used to fetch the source code of a Rust crate from a registry.

cargo clone [FLAGS] [OPTIONS] <crate>... [-- <directory>]

cargo-clone is a Cargo subcommand.

Installation & upgrading

cargo install cargo-clone


cargo clone [FLAGS] [OPTIONS] <crate>... [-- <directory>]

To download cargo-clone's code you would use

cargo clone cargo-clone

Specifying versions

The latest available version is downloaded by default. If specific versions are desired, semver specifiers can be appended to crate names.

cargo clone cargo-clone@1.0.0

Versions are matched exactly by default, but other kinds of matching are also allowed.

cargo clone cargo-clone@~1.0.0

Cloning from git repositories

Using the --git flag runs git clone on each git repository url extracted from crate's metadata.

These lines are roughly equivalent:

cargo clone --git cargo-clone
git clone https://github.com/janlikar/cargo-clone

The command fails if a crate does not have the repository field set to a valid git repository.

Output directory

Crates are downloaded into $PWD/$CRATE_NAME by default.

The output dir can be specified as the last argument:

cargo clone cargo-clone -- foo  # Downloads into $PWD/foo

If multiple packages are downloaded at the same time or if the directory contains a trailing slash, the packages will be downloaded into subdirectories of the path provided.

cargo clone cargo-clone -- pkgs/  # Creates pkgs/cargo-clone/
cargo clone cargo serde -- pkgs2/  # Creates pkgs/cargo and pkgs/serde


Contributions are welcome. Feel free to open a PR into develop branch.

When running locally, you can run using cargo run -- clone CRATE or cargo-clone clone CRATE.

By opening a PR you agree to license your code under Apache/MIT licenses.


~1M SLoC