Bindings to libgit2 for interoperating with git repositories. This library is both threadsafe and memory safe and allows both reading and writing git repositories.

71 releases

✓ Uses Rust 2018 edition

new 0.10.2 Nov 20, 2019
0.10.0 Aug 20, 2019
0.9.2 Jul 24, 2019
0.8.0 Dec 13, 2018
0.0.1 Nov 14, 2014

#1 in #git

Download history 23167/week @ 2019-08-07 24792/week @ 2019-08-14 26214/week @ 2019-08-21 25141/week @ 2019-08-28 28031/week @ 2019-09-04 26989/week @ 2019-09-11 28177/week @ 2019-09-18 28812/week @ 2019-09-25 30981/week @ 2019-10-02 32838/week @ 2019-10-09 29701/week @ 2019-10-16 31067/week @ 2019-10-23 30684/week @ 2019-10-30 32919/week @ 2019-11-06 31996/week @ 2019-11-13

126,393 downloads per month
Used in 285 crates (213 directly)


138K SLoC

C 121K SLoC // 0.1% comments Rust 17K SLoC // 0.2% comments Shell 327 SLoC // 0.1% comments



libgit2 bindings for Rust

git2 = "0.10"

Rust version requirements

git2-rs works with stable Rust, and typically works with the most recent prior stable release as well. Check the MSRV job of the CI script to see the oldest version of Rust known to pass tests.

Version of libgit2

Currently this library requires libgit2 0.28.2. 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.

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. To automate tests and handle proper stashing and unstashing of unstaged changes and thus avoid nasty surprises, use the pre-commit hook found here and place it into the .git/hooks/ with the name pre-commit. You may need to add execution permissions with chmod +x.

To skip tests on a simple commit or doc-fixes, use git commit --no-verify.

Building on OSX 10.10+

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


This project is licensed under either of

at your option.


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.


~102K SLoC