Skip to content
This repository

Node bindings to the libgit2 project.


Node bindings to the libgit2 project.


Stable: 0.1.1

Maintained by Tim Branyen @tbranyen, Michael Robinson @codeofinterest, and Nick Kallen @nk, with help from awesome contributors!

API Documentation.

Building and Installing.


npm install nodegit

Building manually:

If you wish to help contribute to nodegit it is useful to build locally.

# Fetch this project.
git clone git://

# Enter the repository.
cd nodegit

# Install the template engine, run the code generation script, and install.
npm install ejs && npm run codegen && npm install

If you encounter errors, you most likely have not configured the dependencies correctly.

Installing dependencies:

Using Brew on OS X:

brew install cmake libzip

Using APT on Ubuntu:

sudo apt-get install cmake libzip-dev build-essential

API examples.

Cloning a repository and reading a file:

var clone = require("nodegit").Repo.clone;

// Clone a given repository into a specific folder.
clone("", "tmp", null, function(err, repo) {
  if (err) {
    throw err;

  // Use a known commit sha from this repository.
  var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";

  // Look up this known commit.
  repo.getCommit(sha, function(err, commit) {
    if (err) {
      throw error;

    // Look up a specific file within that commit.
    commit.getEntry("", function(err, entry) {
      if (err) {
        throw error;

      // Get the blob contents from the file.
      entry.getBlob(function(err, blob) {
        if (err) {
          throw err;

        // Show the name, sha, and filesize in byes.
        console.log( + entry.sha() + blob.size() + "b");

        // Show a spacer.
        console.log(Array(72).join("=") + "\n\n");

        // Show the entire file.

Emulating git log:

var open = require("nodegit");

// Open the repository directory.
open("tmp", function(err, repo) {
  if (err) {
    throw err;

  // Open the master branch.
  repo.getMaster(function(err, branch) {
    if (err) {
      throw err;

    // Create a new history event emitter.
    var history = branch.history();

    // Create a counter to only show up to 9 entries.
    var count = 0;

    // Listen for commit events from the history.
    history.on("commit", function(commit) {
      // Disregard commits past 9.
      if (++count >= 9) {

      // Show the commit sha.
      console.log("commit " + commit.sha());

      // Store the author object.
      var author =;

      // Display author information.
      console.log("Author:\t" + + " <", + ">");

      // Show the commit date.
      console.log("Date:\t" +;

      // Give some space and show the message.
      console.log("\n    " + commit.message());

    // Start emitting events.

Unit tests.

You will need to build locally before running the tests. See above.

npm test
Something went wrong with that request. Please try again.