Client implementation of the "Smart" HTTP Git protocol in pure OCaml

Support for on-disk and in-memory Git stores. Can read and write all the Git
objects: the usual blobs, trees, commits and tags but also the pack files, pack
indexes and the index file (where the staging area lives - only for git-unix

All the objects share a consistent API, and convenience functions are provided
to manipulate the different objects. For instance, it is possible to make a pack
file position independent (as the Zlib compression might change the relative
offsets between the packed objects), to generate pack indexes from pack files,
or to expand the filesystem of a given commit.

The library comes with some command-line tools called ogit-* as a
Proof-of-concept of the core library which shares a similar interface with
git, but where all operations are mapped to the API exposed by ocaml-git (and
hence using only OCaml code). However, these tools are not meant to be used. They
are just examples of how to use ocaml-git.

ocaml-git wants to be a low-level library for irmin. By this fact,
high-level processes such as a (patience) diff, git status,
etc. are not implemented.

As a MirageOS project, ocaml-git is system agnostic. However, it provides a
git-unix package which uses UNIX syscall and it able to introspect a Git
repository as you usually know. However, ocaml-git handles only Git objects
and it does not populate your filesystem as git does.

For example, Git_unix.Sync.clone does not give you files of your repository
but synchronize your .git with your repository.

The API documentation is available online.

Build, Install Instructions and Packages

To build and install the project, simply run:

$ opam install git
$ opam install git-unix
$ opam install git-mirage


ocaml-git uses 2 libraries with the linking-trick:

These libraries provide a C implementation and an OCaml implementation (mostly
to be compatible with js_of_ocaml). However, utop or any a build-system such
as ocamlbuild are not able to choose between these implementations. So, you
must explicitely choose one.

These libraries use virtual-library available with dune. If
your build-system is dune, you should not have any problem about that where
dune is able to take the default implementation of these libraries.

What is supported

  • The loose object files can be read and written;

  • The PACK files (collections of compressed loose objects using a
    binary-diff representation) and PACK indexes (indexes of pack
    files) can be read and written). The binary diff hunks are exposed using a
    high-level position-independent representation so that they can be manipulated
    more easily. Pack file can be created and is compressed.

  • The INDEX file (used as for managing the staging area) are fully
    supported. Which means that git diff and git status will work as expected
    on a repository created by the library. This feature is only available for
    git-unix when it needs to introspect a file-system.

  • Cloning and fetching (using various options) are fully supported
    for the Git protocol, the smart-HTTP protocol and git+ssh. A subset of the
    protocol capabilities are implemented (mainly thin-pack, ofs-delta,
    side-band-64k and allow-reachable-sha1-in-want).

  • Pushing is still experimental and needs more testing.

  • An abstraction for Git Store
    Is available. Various store implementations are available:

What is not supported

  • No server-side operations are currently supported.

  • No GC.

  • Updates, merge and rebase are not supported. Use irmin instead.


Performance is comparable to the Git tool.


This utop example must run into the ocaml-git repository when the given path
is ..

# #require "checkseum.c" ;;
# #require "digestif.c" ;;
# #require "git-unix" ;;
# open Git_unix ;;
# module Search = Git.Search.Make(Store) ;;

# let read filename =
    let open Lwt_result.Infix in
    Store.v (Fpath.v ".") >>= fun t ->
    Store.Ref.resolve t Store.Reference.master >>= fun head ->
    let open Lwt.Infix in
    Search.find t head (`Commit (`Path filename)) >>= function
    | None -> Lwt.return (Error `Not_found)
    | Some hash -> t hash
val read : string list -> (Store.Value.t, Store.error) Lwt_result.t
# let pp =
    let ok ppf = function
      | Store.Value.Blob blob ->
        Fmt.string ppf (Store.Value.Blob.to_string blob)
      | _ -> Fmt.string ppf "#git-object" in
    Fmt.result ~ok ~error:Store.pp_error
val pp : (Store.Value.t, Store.error) Fmt.t

# Lwt.Infix.(read [ "" ] >|= pp Fmt.stdout) ;;

ocaml-git -- Git format and protocol in pure OCaml

Support for on-disk and in-memory Git stores. Can read and write all
the Git objects: the usual blobs, trees, commits and tags but also
the pack files, pack indexes and the index file (where the staging area



MIT, see file for its text.

30 Jun 2020
>= "1.0.0" & < "3.0.0"
>= "1.0.0" & < "3.0.0"
= version
>= "4.07.0"
Reverse Dependencies
!= "1.11.4" & < "2.1.0" | = "2.1.3"
>= "1.10.0" & < "1.11.4" | = "2.1.3"