# libgit2 — Cross-Platform Linkable Git Library in C > A portable, pure C implementation of the Git core methods that can be linked into any application to provide Git functionality without shelling out to the git binary. ## Install Save in your project root: # libgit2 — Cross-Platform Linkable Git Library in C ## Quick Use ```bash # Build from source git clone https://github.com/libgit2/libgit2.git cd libgit2 && mkdir build && cd build cmake .. && cmake --build . # Or install via package manager brew install libgit2 # macOS apt install libgit2-dev # Debian/Ubuntu ``` ## Introduction libgit2 is a portable, pure C implementation of the Git core methods provided as a linkable library. It allows applications to interact with Git repositories programmatically without requiring the git command-line tool, and it powers Git integrations in editors, IDEs, and services worldwide. ## What libgit2 Does - Provides a complete C API for reading and writing Git repositories - Supports cloning, fetching, pushing, and all standard Git operations - Offers bindings for dozens of languages including Rust, Python, Ruby, C#, and Node.js - Handles Git objects, references, index manipulation, and merge operations - Implements custom transport and credential callback mechanisms ## Architecture Overview libgit2 is structured as a layered C library with a public API surface, an internal object database layer, and pluggable backends for storage and networking. It uses a thread-safe design with no global state, making it suitable for embedding in multi-threaded applications. Transport layers (HTTP, SSH, local) are modular and can be replaced or extended. ## Self-Hosting & Configuration - Build with CMake on any platform (Linux, macOS, Windows, BSD) - Link against your application as a shared or static library - Configure SSL backend (OpenSSL, mbedTLS, or platform-native) - Set up SSH support via libssh2 for remote operations - Use language bindings like Rugged (Ruby), pygit2 (Python), or git2-rs (Rust) ## Key Features - Zero dependency on the git binary — fully self-contained - Thread-safe design with no global mutable state - Extensive language binding ecosystem across 20+ languages - Custom backend support for object storage and references - Battle-tested in production by GitHub, GitLab, Visual Studio, and Xcode ## Comparison with Similar Tools - **git CLI** — full-featured but requires subprocess calls and output parsing - **JGit** — Java-only Git implementation, heavier runtime - **go-git** — Go-native Git library, no C FFI needed but Go-specific - **gitoxide (gix)** — newer Rust-native Git implementation, still maturing - **dulwich** — pure Python Git implementation, slower for large repos ## FAQ **Q: Which products use libgit2 in production?** A: GitHub Desktop, Visual Studio, Xcode, GitKraken, Sublime Merge, and many CI/CD systems rely on libgit2. **Q: Does libgit2 support all Git features?** A: It covers the vast majority of Git operations. Some advanced features like interactive rebase require the git CLI. **Q: How do I use libgit2 from my programming language?** A: Use the official or community-maintained bindings: Rugged for Ruby, pygit2 for Python, git2-rs for Rust, LibGit2Sharp for C#/.NET, or NodeGit for Node.js. **Q: Is libgit2 compatible with repositories created by git?** A: Yes. libgit2 reads and writes standard Git repository formats and is fully interoperable with the git CLI. ## Sources - https://github.com/libgit2/libgit2 - https://libgit2.org --- Source: https://tokrepo.com/en/workflows/asset-b864ad36 Author: AI Open Source