NAME

Git::Native - Native Git for Perl via libgit2 (FFI, no fork/exec)

VERSION

version 0.003

SYNOPSIS

use Git::Native;

my $repo = Git::Native->open('/path/to/.git');
my $main = $repo->reference('refs/heads/main');
say $main->target;     # commit OID

# Build a commit without forking git
my $blob_oid = $repo->blob_create_frombuffer("hello\n");
my $tb       = $repo->tree_builder;
$tb->insert(name => 'hi.txt', oid => $blob_oid, mode => 0100644);
my $tree_oid = $tb->write;
my $commit_oid = $repo->commit_create(
  update_ref => 'HEAD',
  tree       => $tree_oid,
  parents    => [$main->target],
  message    => 'add greeting',
);

DESCRIPTION

Git::Native is a Moo wrapper around Git::Libgit2 (which binds libgit2 via FFI::Platypus). Use it instead of Git::Wrapper or Git::Repository when you want to do Git work without forking the git binary on every operation.

Contrast: - Git::Wrapper, Git::Repository: shell out to git - Git::Raw: XS bindings, unmaintained since 2022, known segfaults - Git::PurePerl: pure-Perl read-only, no push/pull

open

my $repo = Git::Native->open($path);

Open an existing repository at $path. Returns a Git::Native::Repository.

open_ext

my $repo = Git::Native->open_ext($start_path, %opts);

Same as git_repository_open_ext — walks up from $start_path. flags and ceiling_dirs are forwarded.

init

my $repo = Git::Native->init($path, bare => 1);

Initialise a new repository. bare => 1 creates a bare repo.

reference_name_is_valid

Git::Native->reference_name_is_valid('refs/heads/main');   # 1
Git::Native->reference_name_is_valid('refs/bad..name');    # 0

Class method. Returns true if libgit2 considers $name a valid reference name. No repository handle required.

SEE ALSO

Alien::Libgit2, Git::Libgit2, FFI::Platypus, libgit2

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-git-native/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.