0

Let's say I have checked out a git repository locally and I would like to add a specific branch/tag as a dependency to a Cargo.toml of a rust codebase. Is there a way to do it?

I've already tried the following without success:

dep = { path = "../path/to/git/repo", branch = "hello-world" }
dep = { path = "../path/to/git/repo", rev = "12345" }
E_net4
  • 27,810
  • 13
  • 101
  • 139
mp01
  • 1

2 Answers2

0

path is for path dependencies. You should use git with an absolute path for local git dependencies:

# Cargo.toml
dep = { git = "file:///absolute/path/to/git/repo", rev = "12345" }
Weihang Lo
  • 59
  • 2
  • 5
0

You can only use branch if your git dependency specifies a remote server. If it does, then this works

# Cargo.toml
dep = { git = https://<path_to_remove_git_repo>.git", branch = "hello-world" }

If you use path to specify a dependency, the code on your local machine will be read, so it would depend on which branch was checked out (loaded) on your local machine.

Thorkil Værge
  • 2,727
  • 5
  • 32
  • 48
  • For the options when specifying a git dependency see: See https://github.com/rust-lang/cargo/issues/126#issuecomment-48101852 – Thorkil Værge Aug 16 '23 at 12:41