Skip to content
pubscout

git2dart

0.5.6, released 3 months ago by dartgit.dev

Dart bindings to libgit2 for working with Git repositories via FFI.

$ flutter pub add git2dart
Source repository

What it does

Provides a null-safe Dart API for interacting with Git repositories directly via libgit2 through FFI. Supports repository lifecycle, git objects, working trees, indexes, references, and remotes without shelling out to the git executable.

AI-written summary of version 0.5.6, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to build desktop Flutter apps or CLI tools that perform Git operations.
  • You want to manage Git repositories natively without calling the system `git` command-line tool.

Skip it when

  • You are building web applications (not supported by FFI library bindings to libgit2).
  • You only need simple file operations and have no requirement for Git integration.

Strengths

  • Comprehensive coverage of libgit2 functionality including branches, remotes, merge, rebase, and status.
  • Prebuilt binaries and generated FFI bindings simplify setup across supported platforms.

Weaknesses

  • Requires platform-specific native dependencies (like OpenSSL and PCRE on Linux) to be installed.
  • Manual memory management (calling `free()`) is required for long-running tools and apps to prevent leaks.

Setup

Kind
FFI (native library)
Effort
Medium
Code generation
No
Direct dependencies
5

Requires platform setup (e.g. OpenSSL and PCRE on Linux, Homebrew OpenSSL on macOS, Chocolatey OpenSSL on Windows) and mobile platform initialization via PlatformSpecific.initialize().

import 'dart:io';
import 'package:git2dart/git2dart.dart';

Future<void> main() async {
  print('libgit2 ${Libgit2.version}');
  final directory = await Directory.systemTemp.createTemp('git2dart-example');
  final repo = Repository.init(path: directory.path);
  final oid = Blob.create(repo: repo, content: 'Hello from git2dart\n');
  final blob = Blob.lookup(repo: repo, oid: oid);
  print('Repository: ${repo.path}');
  print('Blob: ${blob.oid.sha}');
  blob.free();
  repo.free();
  await directory.delete(recursive: true);
}

Alternatives

Packages that do the same job and could replace git2dart.

  • pdfium_dart

    Dart FFI bindings for the PDFium library providing low-level C API access.

  • printing_ffi

    Flutter plugin for direct printer communication and print job management via native FFI bindings.

Works with

Packages commonly used together with git2dart: ones it builds on, ones built on it, and its own family.