Publishing a C or C++ library so that others can consume it with a package manager has always required some infrastructure. You contribute a recipe to ConanCenter, or you set up a server, or at the very least you host a local recipes index. That is the right trade-off for most cases, but it is a bit of ceremony when you only want to say: “my project needs that library, which lives in that GitHub repository”.

Conan 2.35 adds an experimental feature for exactly this: git requirements. A requirement can now point directly to a GitHub repository, and Conan will clone it, export its recipe and build it. No Conan server and no remotes configured.

Important: git requirements are designed for the open source community. Their use in production by companies and organizations is discouraged. We will come back to why, and to what to use instead, at the end of this post.

The idea

If a library’s repository contains a conanfile.py at its root, that repository already is a Conan “package source”. Consumers just need to say where it is, with the new git argument of self.requires():

from conan import ConanFile


class App(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeConfigDeps", "CMakeToolchain"

    def requirements(self):
        self.requires("mathlib/1.0", git="conan-io/conanci_mathlib")

You can try this right now: conan-io/conanci_mathlib is a small C++ library with a conanfile.py at the root of its repository, and nothing else. The value of git is <organization or user>/<repository>, and the repository is always cloned from https://github.com/conan-io/conanci_mathlib.git. Then, as usual:

$ conan install . --build=missing
...
mathlib/1.0: Not found in local cache, resolving from git remote 'https://github.com/conan-io/conanci_mathlib.git'
...
mathlib/1.0: Using git commit as the recipe revision: <commit>
mathlib/1.0: Exported: mathlib/1.0#<commit>

The second time you run it, the recipe is already in the cache and GitHub is not contacted at all.

Diagram: a project declares a requirement with the git argument, Conan clones the repository from GitHub, exports the recipe with the git commit as revision and builds from source, while the Conan server box is crossed out as not involved

This is how it works under the hood:

  1. Conan runs git (so it must be installed) to clone the repository into the git_clones folder of the Conan cache, checking out the requested ref.
  2. The conanfile.py is exported as conan export would do, but the recipe revision is forced to be the git commit, like revision_mode = "scm".
  3. The graph is computed as if the recipe had been found in a remote, with that commit as its revision. There are no binaries anywhere, so packages are built from source, typically with --build=missing.

Why this matters for open source

For a library author, publishing becomes: add a conanfile.py to the root of the repository, and tell people the line to copy. There is no upload step, no account, no review queue. And for consumers, there is nothing to configure either: no conan remote add, no credentials, and it even works with --no-remote.

Git requirements also resolve transitively. The ai library in conan-io/conanci_ai depends on mathlib. Today its recipe declares that with a plain requires = "mathlib/[>=1.0 <2]", expecting the package to be in a Conan server. If it wanted to be consumable from GitHub only, the recipe would declare where its dependency lives:

def requirements(self):
    self.requires("mathlib/[>=1.0 <2]", git="conan-io/conanci_mathlib")

A consumer would then just write self.requires("ai/1.0", git="conan-io/conanci_ai"), which is the case shown in the diagram above, and doesn’t need to know anything about mathlib. Conan clones each repository once, and later paths to it find it in the cache. This is a very natural way to describe the relationships between open source projects: each project says where its dependencies live, and the whole graph can be resolved starting from a few lines in the final application.

A natural fit for AI agents

There is a second audience we find interesting. AI coding agents are increasingly asked to “add library X to this C++ project”, and until now, the answer involved a lot of context outside the repository: which server, which remote, which credentials, is there a recipe for it in ConanCenter, and in which version?

With git requirements, an agent only needs two things that it can verify by itself: the name of the GitHub repository, and a ref. If the repository has a conanfile.py in its root, a single line in the conanfile.py of the project is enough, with nothing to provision beforehand. And because the result is plain text in the repository, a human can review exactly what was added in the pull request. That “can review” part matters, because the same properties that make this convenient for an agent are the reasons to be careful with it, which we cover below.

The git argument is only a hint

One design decision is important to understand: the requirement is still mathlib/1.0. The git argument is not the identity of the package, it is a hint about where to find it when Conan doesn’t have it. Conan resolves a requirement with a git argument in this order:

  1. Mechanisms that redefine the requirement win and git is ignored: editable packages, [replace_requires] in a profile that replaces it with a different package, or [platform_requires].
  2. The local cache. If the recipe is there, whatever its origin, it is used and the repository is not contacted.
  3. The Git repository, only if it is not in the cache. Conan clones it and exports the recipe. Remotes are not used to find the recipe, even if one of them has mathlib/1.0.

Left: the resolution order of a git requirement, first redefinitions such as editables or replace_requires, then the local cache, then cloning from GitHub. Right: a scale of pinning from the default branch, to a branch, a tag, a commit and a lockfile

A direct consequence is that changing the ref in your conanfile.py (say, from @v1 to @v2) has no effect while the recipe is in the cache. You need --update or conan remove "mathlib/1.0" -c to make Conan look at the repository again.

Choosing the version: branches, tags and commits

The git argument accepts an optional ref after an @:

git= value What you get
"conan-io/conanci_mathlib" The latest commit of the default branch
"conan-io/conanci_mathlib@main" The latest commit of the main branch
"conan-io/conanci_mathlib@v1.0" The commit the v1.0 tag points to
"conan-io/conanci_mathlib@<commit>" That exact commit

The conanci_mathlib repository doesn’t have tags, so the @v1.0 row is only illustrative, while @main and a commit work with it as they are.

If the recipe declares its own name and version, they must match the requirement, otherwise Conan raises an error. Take into account that the default branch is usually ahead of the last release: if main already says 1.1 and you ask for mathlib/1.0 without a ref, it fails. Use @v1.0, or a version range.

Version ranges are supported too, self.requires("mathlib/[>=1.0 <2]", git="conan-io/conanci_mathlib"), with a caveat: the range doesn’t choose among several versions. The repository at the given ref provides exactly one version, and Conan checks that it falls inside the range.

Reproducibility: pinning commits and lockfiles

The recipe revision of a git package is the commit, and it is what you see in the output and in lockfiles, as mathlib/1.0#<commit>. This gives several ways to make builds reproducible, from loose to strict:

  • Branches and tags are not enough. Branches move, and tags can be moved too. Only a commit is immutable. Even so, the local cache keeps being used, so a branch ref only fetches new commits when you ask with --update.
  • Use a commit ref, git="conan-io/conanci_mathlib@<commit>", or pin the revision in the requirement: self.requires("mathlib/1.0#<commit>", git="conan-io/conanci_mathlib"). In this second case Conan looks for that exact revision in the cache, and falls back to the repository even when a different revision of the same recipe is cached, for example one downloaded from a remote. Defining both a revision and a ref is an error.
  • Use lockfiles. A lockfile stores the commit as the recipe revision of every git requirement in the graph:

    $ conan install . --build=missing --lockfile-out=conan.lock
    # ... weeks later, the branch has moved on and the cache was cleaned ...
    $ conan install . --build=missing --lockfile=conan.lock
    

    The second command builds the original commit, even if the branch has advanced since. Committing conan.lock to the repository gives the whole project, transitive git requirements included, a precise and reviewable snapshot of the exact commits it was built with.

This is a solid way for an open source project to get reproducible CI and releases. But please keep in mind what it is not: a commit hash guarantees which source you build, not that such source will correctly build for the current configuration neither that the repository will still exist tomorrow, and as we will see, there are no binaries and no copy of the recipe other than the local cache of each machine.

Limitations and usage recommendations

There are a few limitations to be aware of. The most important one is that there are no binaries: packages are built from source on each machine, as there is nowhere to upload them, and sharing binaries requires a Conan server such as Artifactory. Also, there can be only one recipe per repository, a conanfile.py at the root. The rest of the limitations are listed in the Requirements from Git repositories documentation.

Also, a git requirement is only a pointer to a repository. There is no server, no binaries, no control over what is served, and no immutability guarantees. The recipe is Python code that is downloaded from the internet and executed in your machine, with no filter other than the ref used, and without the pre_export and post_export hooks that an organization might use for policies, signing or scanning.

Companies and organizations typically need to control the origin and lifecycle of third-party dependencies, to have reproducible builds, to scan, audit and sign recipes and packages, and to be protected from external changes and outages. Git requirements are not designed for any of that. For non open source usage and real production usage, a Conan server such as an Artifactory server is needed, under your control. Use instead:

Note also that recipes from any source, including third parties, can use git in their requirements, so an organization that wants to block it needs to review the recipes of its dependencies. See also the security guidelines.

Conclusion

Git requirements lower the bar for sharing and consuming C and C++ libraries in the open source world to its minimum: a conanfile.py in your repository, and a line with git="user/repo" in the consumer. Transitive resolution lets projects describe their relationships among themselves, commits and lockfiles give a path to reproducibility, and the absence of infrastructure makes it a natural fit for quick prototypes, open source projects and AI assistants adding dependencies. For everything that involves organizations, production and controlled supply chains, an Artifactory server is needed: keep using ConanCenter and your own Artifactory server.

The details are in the Requirements from Git repositories documentation. The feature is experimental and available since Conan 2.35, so your feedback can still shape it. Please try it and open issues in github.com/conan-io/conan.