1 libgit2 - the Git linkable library
2 ==================================
6 | **master** branch CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=master)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=master) |
7 | **v0.28 branch** CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=maint/v0.28)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=maint/v0.28) |
8 | **v0.27 branch** CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=maint/v0.27)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=maint/v0.27) |
9 | **v0.26 branch** CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=maint/v0.26)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=maint/v0.26) |
10 | **Nightly** builds | [![Azure Pipelines Build Status](https://libgit2.visualstudio.com/libgit2/_apis/build/status/nightly?branchName=master&label=Full+Build)](https://libgit2.visualstudio.com/libgit2/_build/latest?definitionId=9&branchName=master) [![Coverity Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/coverity?branchName=master&label=Coverity+Build)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=21?branchName=master) [![Coverity Scan Build Status](https://scan.coverity.com/projects/639/badge.svg)](https://scan.coverity.com/projects/639) |
12 `libgit2` is a portable, pure C implementation of the Git core methods
13 provided as a linkable library with a solid API, allowing to build Git
14 functionality into your application. Language bindings like
15 [Rugged](https://github.com/libgit2/rugged) (Ruby),
16 [LibGit2Sharp](https://github.com/libgit2/libgit2sharp) (.NET),
17 [pygit2](http://www.pygit2.org/) (Python) and
18 [NodeGit](http://nodegit.org) (Node) allow you to build Git tooling
19 in your favorite language.
21 `libgit2` is used to power Git GUI clients like
22 [GitKraken](https://gitkraken.com/) and [gmaster](https://gmaster.io/)
23 and on Git hosting providers like [GitHub](https://github.com/),
24 [GitLab](https://gitlab.com/) and
25 [Azure DevOps](https://azure.com/devops).
26 We perform the merge every time you click "merge pull request".
28 `libgit2` is licensed under a **very permissive license** (GPLv2 with a special
29 Linking Exception). This basically means that you can link it (unmodified)
30 with any kind of software without having to release its source code.
31 Additionally, the example code has been released to the public domain (see the
32 [separate license](examples/COPYING) for more information).
37 * [Quick Start](#quick-start)
38 * [Getting Help](#getting-help)
39 * [What It Can Do](#what-it-can-do)
40 * [Optional dependencies](#optional-dependencies)
41 * [Initialization](#initialization)
42 * [Threading](#threading)
43 * [Conventions](#conventions)
44 * [Building libgit2 - Using CMake](#building-libgit2---using-cmake)
45 * [Building](#building)
46 * [Installation](#installation)
47 * [Advanced Usage](#advanced-usage)
48 * [Compiler and linker options](#compiler-and-linker-options)
51 * [Language Bindings](#language-bindings)
52 * [How Can I Contribute?](#how-can-i-contribute)
58 **Prerequisites** for building libgit2:
60 1. [CMake](https://cmake.org/), and is recommended to be installed into
62 2. [Python](https://www.python.org) is used by our test framework, and
63 should be installed into your `PATH`.
64 3. C compiler: libgit2 is C90 and should compile on most compilers.
65 * Windows: Visual Studio is recommended
66 * Mac: Xcode is recommended
67 * Unix: gcc or clang is recommended.
71 1. Create a build directory beneath the libgit2 source directory, and change
72 into it: `mkdir build && cd build`
73 2. Create the cmake build environment: `cmake ..`
74 3. Build libgit2: `cmake --build .`
76 Trouble with these steps? Read our [troubleshooting guide](docs/troubleshooting.md).
77 More detailed build guidance is available below.
84 - via IRC: join [#libgit2](https://webchat.freenode.net/#libgit2) on Freenode
85 - via Slack: visit [slack.libgit2.org](http://slack.libgit2.org/) to sign up,
86 then join us in `#libgit2`
90 If you have questions about the library, please be sure to check out the
91 [API documentation](http://libgit2.github.com/libgit2/). If you still have
92 questions, reach out to us on Slack or post a question on
93 [StackOverflow](http://stackoverflow.com/questions/tagged/libgit2) (with the `libgit2` tag).
97 Please open a [GitHub Issue](https://github.com/libgit2/libgit2/issues) and
98 include as much information as possible. If possible, provide sample code
99 that illustrates the problem you're seeing. If you're seeing a bug only
100 on a specific repository, please provide a link to it if possible.
102 We ask that you not open a GitHub Issue for help, only for bug reports.
104 **Reporting Security Issues**
106 Please have a look at SECURITY.md.
111 libgit2 provides you with the ability to manage Git repositories in the
112 programming language of your choice. It's used in production to power many
113 applications including GitHub.com, Plastic SCM and Azure DevOps.
115 It does not aim to replace the git tool or its user-facing commands. Some APIs
116 resemble the plumbing commands as those align closely with the concepts of the
117 Git system, but most commands a user would type are out of scope for this
118 library to implement directly.
120 The library provides:
122 * SHA conversions, formatting and shortening
123 * abstracted ODB backend system
124 * commit, tag, tree and blob parsing, editing, and write-back
127 * index file (staging area) manipulation
128 * reference management (including packed references)
129 * config file management
130 * high level repository management
131 * thread safety and reentrancy
132 * descriptive and detailed error messages
133 * ...and more (over 175 different API calls)
135 As libgit2 is purely a consumer of the Git system, we have to
136 adjust to changes made upstream. This has two major consequences:
138 * Some changes may require us to change provided interfaces. While we try to
139 implement functions in a generic way so that no future changes are required,
140 we cannot promise a completely stable API.
141 * As we have to keep up with changes in behavior made upstream, we may lag
142 behind in some areas. We usually to document these incompatibilities in our
143 issue tracker with the label "git change".
145 Optional dependencies
146 =====================
148 While the library provides git functionality without the need for
149 dependencies, it can make use of a few libraries to add to it:
151 - pthreads (non-Windows) to enable threadsafe access as well as multi-threaded pack generation
152 - OpenSSL (non-Windows) to talk over HTTPS and provide the SHA-1 functions
153 - LibSSH2 to enable the SSH transport
154 - iconv (OSX) to handle the HFS+ path encoding peculiarities
159 The library needs to keep track of some global state. Call
163 before calling any other libgit2 functions. You can call this function many times. A matching number of calls to
165 git_libgit2_shutdown();
167 will free the resources. Note that if you have worker threads, you should
168 call `git_libgit2_shutdown` *after* those threads have exited. If you
169 require assistance coordinating this, simply have the worker threads call
170 `git_libgit2_init` at startup and `git_libgit2_shutdown` at shutdown.
175 See [threading](docs/threading.md) for information
180 See [conventions](docs/conventions.md) for an overview of the external
181 and internal API/coding conventions we use.
183 Building libgit2 - Using CMake
184 ==============================
189 `libgit2` builds cleanly on most platforms without any external dependencies.
190 Under Unix-like systems, like Linux, \*BSD and Mac OS X, libgit2 expects `pthreads` to be available;
191 they should be installed by default on all systems. Under Windows, libgit2 uses the native Windows API
194 The `libgit2` library is built using [CMake](<https://cmake.org/>) (version 2.8 or newer) on all platforms.
196 On most systems you can build the library using the following commands
198 $ mkdir build && cd build
202 Alternatively you can point the CMake GUI tool to the CMakeLists.txt file and generate platform specific build project or IDE workspace.
207 Once built, you can run the tests from the `build` directory with the command
211 Alternatively you can run the test suite directly using,
215 Invoking the test suite directly is useful because it allows you to execute
216 individual tests, or groups of tests using the `-s` flag. For example, to
219 $ ./libgit2_clar -sindex
221 To run a single test named `index::racy::diff`, which corresponds to the test
222 function [`test_index_racy__diff`](https://github.com/libgit2/libgit2/blob/master/tests/index/racy.c#L23):
224 $ ./libgit2_clar -sindex::racy::diff
226 The test suite will print a `.` for every passing test, and an `F` for any
227 failing test. An `S` indicates that a test was skipped because it is not
228 applicable to your platform or is particularly expensive.
230 **Note:** There should be _no_ failing tests when you build an unmodified
231 source tree from a [release](https://github.com/libgit2/libgit2/releases),
232 or from the [master branch](https://github.com/libgit2/libgit2/tree/master).
233 Please contact us or [open an issue](https://github.com/libgit2/libgit2/issues)
234 if you see test failures.
239 To install the library you can specify the install prefix by setting:
241 $ cmake .. -DCMAKE_INSTALL_PREFIX=/install/prefix
242 $ cmake --build . --target install
247 For more advanced use or questions about CMake please read <https://cmake.org/Wiki/CMake_FAQ>.
249 The following CMake variables are declared:
251 - `BIN_INSTALL_DIR`: Where to install binaries to.
252 - `LIB_INSTALL_DIR`: Where to install libraries to.
253 - `INCLUDE_INSTALL_DIR`: Where to install headers to.
254 - `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
255 - `BUILD_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON)
256 - `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
258 To list all build options and their current value, you can do the
261 # Create and set up a build directory
264 # List all build options and their values
267 Compiler and linker options
268 ---------------------------
270 CMake lets you specify a few variables to control the behavior of the
271 compiler and linker. These flags are rarely used but can be useful for
272 64-bit to 32-bit cross-compilation.
274 - `CMAKE_C_FLAGS`: Set your own compiler flags
275 - `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries
276 - `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`:
277 Tell CMake where to find those specific libraries
282 If you want to build a universal binary for Mac OS X, CMake sets it
283 all up for you if you use `-DCMAKE_OSX_ARCHITECTURES="i386;x86_64"`
289 Extract toolchain from NDK using, `make-standalone-toolchain.sh` script.
290 Optionally, crosscompile and install OpenSSL inside of it. Then create CMake
291 toolchain file that configures paths to your crosscompiler (substitute `{PATH}`
292 with full path to the toolchain):
294 SET(CMAKE_SYSTEM_NAME Linux)
295 SET(CMAKE_SYSTEM_VERSION Android)
297 SET(CMAKE_C_COMPILER {PATH}/bin/arm-linux-androideabi-gcc)
298 SET(CMAKE_CXX_COMPILER {PATH}/bin/arm-linux-androideabi-g++)
299 SET(CMAKE_FIND_ROOT_PATH {PATH}/sysroot/)
301 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
302 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
303 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
305 Add `-DCMAKE_TOOLCHAIN_FILE={pathToToolchainFile}` to cmake command
309 ==================================
311 Here are the bindings to libgit2 that are currently available:
314 * libqgit2, Qt bindings <https://projects.kde.org/projects/playground/libs/libqgit2/repository/>
316 * chicken-git <https://wiki.call-cc.org/egg/git>
318 * dlibgit <https://github.com/s-ludwig/dlibgit>
320 * GitForDelphi <https://github.com/libgit2/GitForDelphi>
322 * Geef <https://github.com/carlosmn/geef>
324 * git2go <https://github.com/libgit2/git2go>
326 * libgit2-glib <https://wiki.gnome.org/Projects/Libgit2-glib>
328 * Guile-Git <https://gitlab.com/guile-git/guile-git>
330 * hgit2 <https://github.com/jwiegley/gitlib>
332 * Jagged <https://github.com/ethomson/jagged>
334 * LibGit2.jl <https://github.com/JuliaLang/julia/tree/master/stdlib/LibGit2>
336 * luagit2 <https://github.com/libgit2/luagit2>
338 * libgit2sharp <https://github.com/libgit2/libgit2sharp>
340 * nodegit <https://github.com/nodegit/nodegit>
342 * objective-git <https://github.com/libgit2/objective-git>
344 * ocaml-libgit2 <https://github.com/fxfactorial/ocaml-libgit2>
345 * Parrot Virtual Machine
346 * parrot-libgit2 <https://github.com/letolabs/parrot-libgit2>
348 * Git-Raw <https://github.com/jacquesg/p5-Git-Raw>
350 * php-git <https://github.com/libgit2/php-git>
352 * PSGit <https://github.com/PoshCode/PSGit>
354 * pygit2 <https://github.com/libgit2/pygit2>
356 * git2r <https://github.com/ropensci/git2r>
358 * Rugged <https://github.com/libgit2/rugged>
360 * git2-rs <https://github.com/rust-lang/git2-rs>
362 * SwiftGit2 <https://github.com/SwiftGit2/SwiftGit2>
364 * libgit2.vapi <https://github.com/apmasell/vapis/blob/master/libgit2.vapi>
366 If you start another language binding to libgit2, please let us know so
367 we can add it to the list.
369 How Can I Contribute?
370 ==================================
372 We welcome new contributors! We have a number of issues marked as
373 ["up for grabs"](https://github.com/libgit2/libgit2/issues?q=is%3Aissue+is%3Aopen+label%3A%22up+for+grabs%22)
375 ["easy fix"](https://github.com/libgit2/libgit2/issues?utf8=✓&q=is%3Aissue+is%3Aopen+label%3A%22easy+fix%22)
376 that are good places to jump in and get started. There's much more detailed
377 information in our list of [outstanding projects](docs/projects.md).
379 Please be sure to check the [contribution guidelines](docs/contributing.md) to
380 understand our workflow, and the libgit2 [coding conventions](docs/conventions.md).
383 ==================================
385 `libgit2` is under GPL2 **with linking exception**. This means you can link to
386 and use the library from any program, proprietary or open source; paid or
387 gratis. However, if you modify libgit2 itself, you must distribute the
388 source to your modified version of libgit2.
390 See the [COPYING file](COPYING) for the full license text.