Requirements from Git repositories

Warning

This feature is experimental and subject to breaking changes. See the Conan stability section for more information.

New in version 2.35.

Conan can obtain the recipe of a dependency directly from a public GitHub repository, without using any Conan server or remote. The recipe declares, together with the requirement, the repository that contains the conanfile.py of that dependency, using the new git argument (trait) of the requirements:

def requirements(self):
    self.requires("mylib/1.0", git="myuser/mylib")

The git argument is just a hint. The requirement is still mylib/1.0, and it keeps its priority: Conan only uses the repository to obtain the recipe when mylib/1.0 is not already available in the local cache. If it can be resolved from the local cache, the git argument is ignored. Please read the design section to understand how this works and what it implies.

This is an experimental feature, which means that its syntax, behavior and limitations can change in future Conan versions, and those changes will not be considered breaking. Please read the Conan stability section for more information, and report your feedback and use cases in the Conan issue tracker.

Warning

This is a feature designed for the open source community. Its usage in production by companies and organizations is strongly discouraged. A git requirement is just a pointer to a repository on the internet: there is no server, no binaries, no control over what is served, no immutability guarantees, and the recipe hardcodes the origin of its dependencies. Check the limitations and the recommended alternatives for production below.

Use cases

The goal of this feature is to make life easier for open source developers, in two main scenarios:

  • Making a library available to others without any infrastructure. If the library is not included in ConanCenter (yet, or ever), the maintainer only needs to add a conanfile.py at the root of the library repository. Users can then depend on it right away, by adding the git argument to their requirement. There is no need to host a Conan server, to upload any package, to contribute a recipe to ConanCenter, to maintain a local-recipes-index repository, or even to configure any remote with conan remote add in the machine of the users.

  • Defining the relationships between different open source projects. Because the git requirements are resolved transitively, a project can declare its own dependencies in its conanfile.py with git arguments too. The users of that project don’t need to know about those dependencies or to know where they live. Conan will follow the chain of repositories as it computes the dependency graph, again without any server.

Example

Let’s say that we maintain the mylib library, in the https://github.com/myuser/mylib repository. We add to the root of the repository a regular conanfile.py recipe, with the library own sources in the same repository:

conanfile.py at the root of the mylib repository
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout


class MyLibRecipe(ConanFile):
    name = "mylib"
    version = "1.0"
    package_type = "library"
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False]}
    default_options = {"shared": False}
    exports_sources = "CMakeLists.txt", "src/*", "include/*"

    def layout(self):
        cmake_layout(self)

    def generate(self):
        CMakeToolchain(self).generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["mylib"]

Any other user, or another of our projects, can now consume mylib by declaring the requirement and the repository, with the format <organization or user>/<repository>:

conanfile.py of the consumer
from conan import ConanFile

class MyAppRecipe(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeDeps", "CMakeToolchain"

    def requirements(self):
        self.requires("mylib/1.0", git="myuser/mylib")

The first time the consumer is installed, Conan doesn’t find mylib/1.0 in the local cache, so it clones the repository to get its recipe. As the repositories don’t contain binaries, we need to build the package from source:

$ conan install . --build=missing
...
======== Computing dependency graph ========
mylib/1.0: Not found in local cache, resolving from git remote 'https://github.com/myuser/mylib.git'
Cloning git repository 'https://github.com/myuser/mylib.git'...
...
mylib/1.0: Using git commit as the recipe revision: <commit>
Exported: mylib/1.0#<commit> (2026-11-30 12:10:41 UTC)
...

The next time the recipe is already in the local cache, so Conan will not contact GitHub again:

$ conan install . --build=missing
...
======== Computing dependency graph ========
mylib/1.0: Found in cache (configured via git remote 'https://github.com/myuser/mylib.git')
...

The recipes obtained from a Git repository can in turn use the git argument for their own requirements. For example, if mylib depended on another of our libraries, its recipe could contain:

conanfile.py in the mylib repository
def requirements(self):
    self.requires("otherlib/2.0", git="myuser/otherlib")

The MyAppRecipe consumer above does not need to change: Conan will clone myuser/mylib, then it will find the requirement to otherlib, and clone myuser/otherlib. If the same package is reached through different paths of the graph, it is only cloned once, the following ones are found in the local cache.

Design: the git argument is only a hint

Important

The requirement name/version keeps its priority. In self.requires("mylib/1.0", git="myuser/mylib"), the requirement is mylib/1.0, and Conan resolves it as it does with any other requirement. The git argument is only a hint, that Conan uses to obtain the recipe from the repository when mylib/1.0 is not already available in the local cache. If the requirement can be resolved from the local cache, the git argument is ignored.

The git argument doesn’t change what the requirement means, it is not a pin to a source, and it doesn’t define a different kind of dependency. It is a convenience that lets Conan find a recipe that it wouldn’t otherwise have. When Conan resolves a requirement that has a git argument, this is the order of priority:

  1. Mechanisms that redefine the requirement. If the package is in editable mode, if a [replace_requires] of the profile replaces the requirement with a different package (different name, version, user or channel), or if the requirement is in the [platform_requires] of the profile, then that mechanism has priority and the git argument is ignored. Conan informs about it with a message for editables, and with a warning for replacements. Note that for [platform_requires] Conan still clones the repository and exports the recipe, before using the platform requirement. A [replace_requires] that only adds a revision to the same requirement is not a different package, see pinning a commit.

  2. The local cache. If a recipe for the requirement is in the local cache, it is used and the git argument is ignored: the repository is not contacted. It doesn’t matter how the recipe got to the cache: it can be the result of a previous clone, of a conan export or conan create, or it can have been downloaded from a remote.

  3. The Git repository, only if the recipe is not in the local cache. Conan clones the repository and exports the recipe to the local cache. The remotes are not used to find the recipe: if the local cache is empty, the recipe is obtained from the repository even if a configured remote contains the same mylib/1.0. No remote is needed for this, it works even with --no-remote.

This design has some consequences that are important to know:

  • Changing the git argument has no effect while the recipe is in the local cache. If a requirement is changed from git="myuser/mylib@v1" to git="myuser/mylib@v2", Conan will still use the recipe in the cache, that was obtained from v1, until it is refreshed with --update, or removed from the cache with conan remove "mylib/1.0" -c.

  • The origin of the recipe in the cache doesn’t matter. If mylib/1.0 was previously downloaded from a remote, that recipe is used, and the git argument is ignored. Conan will say Found in cache even if the recipe didn’t come from the repository. To use the repository even if a different revision of the recipe is in the local cache, pin the commit.

  • The first requirement resolved wins. If different requirements for the same package in the dependency graph use a different ref, the first one that is resolved provides the recipe, and the others use it, whatever their git argument is.

  • Refreshing the recipe from the repository. The --update argument is the way to ask for it. Each requirement is then resolved from its own ref, and if they end up in different commits of the same package, Conan reports a version conflict. The remotes are checked afterwards, as with any other requirement, but for the exact revision that comes from the repository (the commit), so a recipe obtained from the repository is not replaced by a remote one.

  • Version ranges are the exception. A range cannot be resolved without knowing which version the repository declares. In this case, the repository is always the source of the version, and the local cache and the remotes are not used to choose it: with mylib/[>=1.0 <2] and a remote that contains mylib/1.5, the version declared by the repository is the one that is used. If the cache or the remotes need to take priority, use an exact version. See the details about version ranges.

Syntax

The value of the git argument is a string with the format "<organization or user>/<repository>[@<ref>]":

Value

Source of the recipe

git="myuser/mylib"

The latest commit of the default branch of the repository

git="myuser/mylib@main"

The latest commit of the main branch

git="myuser/mylib@v1.0"

The commit that the v1.0 tag points to

git="myuser/mylib@<commit>"

The given commit

The following rules apply:

  • The repository myuser/mylib is always cloned from https://github.com/myuser/mylib.git. At this moment only repositories in github.com are supported.

  • The recipe must be a conanfile.py located at the root of the repository (at the given ref).

  • The ref is everything after the first @. It must be a single and valid branch, tag or commit name, with no whitespaces, not starting with -, and not containing characters that Git does not allow in the names of references like ~ ^ : ? * [ \ or ... Conan raises an error otherwise, and also if there is a trailing @ with an empty ref.

  • The git argument can be used in self.requires(), and also in self.tool_requires() and self.test_requires(), see the reference of the git trait. It is only available in these methods in conanfile.py recipes. It cannot be used with the requires class attributes, in conanfile.txt files, or in the --requires command line argument.

How it works

Following the order of priority explained above, when Conan finds a requirement with the git argument and the recipe is not in the local cache, while it is computing the dependency graph:

  1. Conan clones the repository (it runs the git executable, so it needs to be installed) in the git_clones folder of the local cache storage, and checks out the ref if there is one.

  2. The conanfile.py is exported to the local cache, as the conan export command would do, but forcing the recipe revision to be the Git commit, as in revision_mode = “scm”.

  3. The dependency graph computation continues as if the recipe had been found in a remote, with the Git commit as the recipe revision of the requirement. Then, the binary has to be built from source, typically with --build=missing.

The clones in the git_clones folder are just scratch space. They are removed by the conan cache clean command, and recreated if necessary. The recipes already exported to the local cache are not affected by this.

Name and version of the package

The requirement defines the name and version that the consumer expects, like mylib/1.0 in self.requires("mylib/1.0", git="myuser/mylib"). The recipe in the repository must be consistent with them:

  • If the recipe declares the name and/or the version, either as attributes or in its set_version() method, they must match the ones in the requirement. If they don’t match, Conan raises an error.

  • If the recipe doesn’t declare the name or the version, the ones of the requirement are used.

  • Version ranges are supported, like self.requires("mylib/[>=1.0 <2]", git="myuser/mylib"). In this case, Conan first clones the repository, then it reads the version that the recipe declares, which must be inside the range, and it uses that version. Note that the range doesn’t choose between several versions: the repository (at the given ref) provides one single version, and Conan only checks that it is inside the range. This requires the recipe to declare its own version.

As Conan needs to read the version declared by the repository, the requirements with a version range are the exception to the design: they don’t use the local cache, nor the remotes, to resolve the version. The recipe is exported again from the existing clone every time (without contacting GitHub), or the repository is cloned again if the clone is no longer in the git_clones folder, for example after a conan cache clean, even if the recipe is in the local cache.

Note

The default branch of a repository is usually ahead of the last released version. If the main branch of mylib is already declaring the version 1.1 but we ask for self.requires("mylib/1.0", git="myuser/mylib"), Conan will fail because the recipe creates mylib/1.1. Use a ref that points to the desired version, like git="myuser/mylib@v1.0", or use a version range like mylib/[>=1.0 <2] if any version in the range is valid.

Revisions, pinning and reproducibility

The recipe revision of the packages obtained from Git is the commit that has been cloned. It is the revision that Conan shows in the output and stores in the lockfiles, like mylib/1.0#<commit>.

As branches and tags can move to different commits, a git requirement without a ref, or with a branch ref, does not guarantee that all the users will get the same recipe. The following mechanisms help with reproducibility:

  • Once a recipe is in the local cache, Conan will keep using it, as the git argument is only a hint. To check the repository for new commits, use the --update argument, for example conan install . --build=missing --update. Conan fetches the new changes in the existing clone, and if there are new commits, the exported recipe has a new revision. If the ref is a full commit, there is nothing to update, as a commit cannot change: Conan does not fetch anything from the existing clone.

  • Use a ref that is a tag or a commit in the git argument. Note that only a commit is immutable, Git tags can be moved. Alternatively, the commit can also be defined as the revision of the requirement, like self.requires("mylib/1.0#<commit>", git="myuser/mylib"). It is an error to define both a revision in the requirement and a ref in the git argument of the same requirement. As the exact revision is searched in the local cache, this also makes Conan use the repository when a different revision of the same recipe is already in the local cache, for example one downloaded from a remote.

  • Use lockfiles. As the lockfile contains the recipe revision, that is the commit, installing with the lockfile will always check out the same commit, even in a clean local cache, and even if the branch has advanced in the meantime.

    $ conan install . --build=missing --lockfile-out=conan.lock
    # the branch of mylib advances, and the local cache is cleaned
    $ conan install . --build=missing --lockfile=conan.lock  # still builds the original commit
    
  • It is possible to pin a commit outside of the recipes, for example in a profile, with [replace_requires] adding the revision to the requirement:

    myprofile
    [replace_requires]
    mylib/1.0: mylib/1.0#<commit>
    

Limitations

This feature is intentionally limited, and it is not a replacement for Conan repositories. Please keep in mind that:

  • It cannot store binaries. The Git repositories only provide the recipes, and the packages have to be built from source in every machine, typically with --build=missing. To share binaries between machines and teams, the recommended way is to use a Conan server, as in any production environment.

  • Only public GitHub repositories are intended to be used (https://github.com/<organization or user>/<repository>.git). Other Git hosting services and custom URLs are not supported. Conan does not manage any credentials, it just runs git clone, so private repositories are not a supported use case.

  • It requires the git executable installed in the system, and network access to github.com when a recipe is obtained for the first time, and whenever it is refreshed (--update). The whole repository is cloned, it is not a shallow clone.

  • The recipe must be a conanfile.py at the root of the repository, so there can only be one recipe per repository.

  • The git argument is only available in the self.requires(), self.tool_requires() and self.test_requires() methods of the recipes. It is not available as an attribute, in conanfile.txt or in the command line.

  • The pre_export and post_export hooks are not executed when the recipes obtained from the repositories are exported.

  • The python_requires of the recipes obtained from a repository are not supported. They are not searched in the remotes, only in the local cache, and the git argument is not available for them. They only work if each python_requires happens to be already in the local cache, otherwise exporting the recipe fails with a Cannot resolve python_requires error.

  • The recipe is not immutable. It can change if the ref is a branch or a tag, or if the repository is modified or removed. Conan doesn’t store the recipes anywhere else than in the local cache of every machine.

  • The origin of the dependencies is hardcoded in the recipes. Conan generally decouples the abstract requirements like mylib/1.0 from the place they are stored in remotes, and that allows to replace and move the packages, to use package promotions, etc. The git argument couples the requirement to a repository, and the only way to change it is to modify the recipe.

Recommendations for production and organizations

Using git requirements in production environments of companies and organizations is strongly discouraged. In these cases, it is typically necessary to control the origin and the lifecycle of the third party dependencies, to have reproducible builds, to scan, audit and sign the recipes and the packages, and to avoid being affected by external changes and outages. Please note that the recipe of a git requirement is Python code that is downloaded from the internet and executed in the machine, with no more filters than the ref that is used, and without the pre_export and post_export hooks that an organization could use for policies, signing or scanning.

The recommended alternatives are:

Note that recipes from any source, including third party ones, can use the git argument in their requirements. If your organization wants to make sure that this feature is not being used, the recipes of the dependencies should be reviewed for it.