# Can I specify that Cargo’s Git dependencies fetch with \`--depth 1\`?

**URL:** <https://internals.rust-lang.org/t/can-i-specify-that-cargo-s-git-dependencies-fetch-with-depth-1/24492>\
**Category:** cargo\
**Created:** [July 27, 2026, 11:21am UTC](https://internals.rust-lang.org/t/can-i-specify-that-cargo-s-git-dependencies-fetch-with-depth-1/24492 "2026-07-27T11:21:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stackinspector](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/stackinspector/32/9487_2.png) [@stackinspector](https://internals.rust-lang.org/u/stackinspector)\
**Post date:** [July 27, 2026, 11:21am UTC](https://internals.rust-lang.org/t/can-i-specify-that-cargo-s-git-dependencies-fetch-with-depth-1/24492/1 "2026-07-27T11:21:41Z")

</div>

After a quick search, it seems the answer is no for the current version of Cargo, so I posted this question on IRLO.

Since I need to use `cksumvfs`—a feature not yet officially supported by rusqlite—I created a fork of rusqlite and tried to add the Git repository URL of that fork to the project’s dependencies. However, since rusqlite is a relatively large project, Cargo appears to fetch the entire history, which significantly slows down the first compilation. This is just a repository with a history of tens of megabytes in size—I can’t even imagine how slow and space-consuming it would be if the repository were hundreds of megabytes or even gigabytes in size. Therefore, using `--depth 1` or fetching only the specific commit needed might be a better option.

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [July 27, 2026, 12:56pm UTC](https://internals.rust-lang.org/t/can-i-specify-that-cargo-s-git-dependencies-fetch-with-depth-1/24492/2 "2026-07-27T12:56:34Z")

</div>

We want this too but have generally been limited by libgit2.

We have unstable support at [Unstable Features - The Cargo Book](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#git)

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [July 27, 2026, 12:58pm UTC](https://internals.rust-lang.org/t/can-i-specify-that-cargo-s-git-dependencies-fetch-with-depth-1/24492/3 "2026-07-27T12:58:51Z")

</div>

Small correction: originally we were limited by a git hosting service advising us against it because of the server load involved with different aspects of the protocol. They no longer raise that objection and so it has just been libgit2.

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jrose/32/9591_2.png) [@jrose](https://internals.rust-lang.org/u/jrose)\
**Post date:** [July 27, 2026, 3:37pm UTC](https://internals.rust-lang.org/t/can-i-specify-that-cargo-s-git-dependencies-fetch-with-depth-1/24492/4 "2026-07-27T15:37:55Z")

</div>

On the flip side, git itself (almost certainly with GitHub's nudging) has shifted towards preferring partial clones over shallow clones, at least if you're going to keep using the repository. (I don't know how Cargo handles multiple dependencies on the same repository across space/packages or time/updates.)

> **[Get up to speed with partial clone and shallow clone](https://github.blog/open-source/git/get-up-to-speed-with-partial-clone-and-shallow-clone/)**
>
> As your Git repositories grow, it becomes harder and harder for new developers to clone and start working on them. Git is designed as a distributed version control system. This means that…

---

<div class="post-metadata">

**Author:** ![stackinspector](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/stackinspector/32/9487_2.png) [@stackinspector](https://internals.rust-lang.org/u/stackinspector)\
**Post date:** [July 28, 2026, 8:53am UTC](https://internals.rust-lang.org/t/can-i-specify-that-cargo-s-git-dependencies-fetch-with-depth-1/24492/5 "2026-07-28T08:53:54Z")

</div>

BTW I noticed that even when I use `.cargo/config.toml` to patch the Git URL to a local path, Cargo still always fetches from the Git URL (even though it actually compiles the local code). Is this an expected behavior? Is there a way to force Cargo to use the local path?

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [July 28, 2026, 11:36am UTC](https://internals.rust-lang.org/t/can-i-specify-that-cargo-s-git-dependencies-fetch-with-depth-1/24492/6 "2026-07-28T11:36:25Z")

</div>

See [cargo accesses original url although overridden by patch · Issue #16574 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/issues/16574)
