libgit2 bindings for Rust https://docs.rs/git2
Find a file
2026-05-18 15:43:48 +00:00
.github/workflows chore(ci): test git2 sha256 support 2026-05-18 16:29:30 +02:00
ci Fix publish not following redirect 2024-03-19 08:39:22 -07:00
examples fix: init example with --object-format option 2026-05-18 16:29:29 +02:00
git2-curl Merge pull request #1168 from joshtriplett/cred-feature 2025-08-12 15:13:47 +00:00
libgit2-sys docs(sys): update changelog for 0.18.4 2026-05-07 21:26:37 -04:00
src fix: import ObjectFormat in one place 2026-05-18 16:32:49 +02:00
systest fix: Add missing argument to git_config_backend::unlock 2026-01-12 01:01:46 -05:00
tests [Result migration] Return Result from StringArray::get() 2026-05-16 14:33:28 -07:00
.gitignore Add a Cargo.lock 2025-01-04 15:56:31 -08:00
.gitmodules Update libgit2 submodule. (#503) 2019-12-11 16:27:05 -08:00
Cargo.lock chore(sys): update libgit2 to 1.9.3 2026-05-04 19:53:29 -04:00
Cargo.toml feat: SHA256 support behind unstable-sha256 feature 2026-05-18 16:29:28 +02:00
CHANGELOG.md docs: changelog for git2@0.21 2026-05-18 17:32:23 +02:00
CONTRIBUTING.md Prepare to rename primary branch to main 2026-04-21 15:02:50 -07:00
FUNDING.json Create FUNDING.json 2024-02-15 12:24:19 -08:00
LICENSE-APACHE Add a MIT/APL2 license 2014-10-01 10:10:15 -07:00
LICENSE-MIT Add a MIT/APL2 license 2014-10-01 10:10:15 -07:00
README.md README.md: replace discussion of missing gist 2026-03-09 01:43:57 -07:00
triagebot.toml Add triagebot 2025-01-20 08:21:47 -08:00

git2-rs

Documentation

libgit2 bindings for Rust.

cargo add git2

Features

By default, git2 includes support for working with local repositories, but does not include network support (e.g. cloning remote repositories). If you want to use features that require network support, you may need the "https" and/or "ssh" features. If you support user-provided repository URLs, you probably want to enable both.

cargo add git2 --features https,ssh

Rust version requirements

git2-rs works with stable Rust, and typically works with the most recent prior stable release as well.

Version of libgit2

Currently this library requires libgit2 1.9.0 (or newer patch versions). The source for libgit2 is included in the libgit2-sys crate so there's no need to pre-install the libgit2 library, the libgit2-sys crate will figure that and/or build that for you. On the other hand, if an appropriate version of libgit2 is present, git2 will attempt to dynamically link it.

To be more precise, the vendored libgit2 is linked statically if two conditions both hold:

  • The environment variable LIBGIT2_NO_VENDOR=1 is not set
  • and either a) The Cargo feature vendored-libgit2 is set or b) an appropriate version of libgit2 cannot be found on the system.

In particular, note that the environment variable overrides the Cargo feature.

Building git2-rs

$ git clone https://github.com/rust-lang/git2-rs
$ cd git2-rs
$ cargo build

Automating Testing

Running tests and handling all of the associated edge cases on every commit proves tedious very quickly. You can use GitHub's automated CI to run the tests on your commit(s) if you do not run them locally.

Building on macOS 10.10+

If the ssh feature is enabled then this library depends on libssh2 which depends on OpenSSL. To get OpenSSL working follow the openssl crate's instructions.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in git2-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.