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

80 releases

0.13.8 Jul 21, 2020
0.13.6 May 19, 2020
0.13.0 Mar 13, 2020
0.11.0 Dec 12, 2019
0.0.1 Nov 14, 2014

#1 in Development tools

Download history 36144/week @ 2020-04-13 39071/week @ 2020-04-20 38405/week @ 2020-04-27 39344/week @ 2020-05-04 43081/week @ 2020-05-11 39447/week @ 2020-05-18 38994/week @ 2020-05-25 43907/week @ 2020-06-01 46851/week @ 2020-06-08 45790/week @ 2020-06-15 43723/week @ 2020-06-22 39822/week @ 2020-06-29 43118/week @ 2020-07-06 33672/week @ 2020-07-13 35232/week @ 2020-07-20 44500/week @ 2020-07-27

176,163 downloads per month
Used in 391 crates (288 directly)


141K SLoC

C 122K SLoC // 0.1% comments Rust 19K SLoC // 0.2% comments Shell 417 SLoC // 0.1% comments Python 157 SLoC // 0.0% comments



libgit2 bindings for Rust

git2 = "0.13"

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 1.0.0. 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