Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Native Node bindings to Git.
JavaScript C++ Other
Latest commit 08564a7 @johnhaley81 johnhaley81 Merge pull request #799 from nodegit/update-libgit2
Bump libgit2 to 0.23.4
Failed to load latest commit information.
.travis TravisCI: Create and push tags
examples Fix typo in cloneFromGithubWith2Factor example
generate Bump libgit2 to 0.23.4
guides Revert "Merge pull request #615 from heavyk/thenify-bluebird"
lib revwalk: Add missing "async" annotations to getCommits() methods
lifecycleScripts bump openssl to whatever nodejs is using
test Make `Branch.setUpstream` and `Branch.upstream` async
vendor Bump libgit2 to 0.23.4
.astylerc prettify generated output
.didntcomefromthenpmregistry overhaul the rest of the build process
.editorconfig Added editor config
.gitignore bump openssl to whatever nodejs is using
.gitmodules Bump libgit2 to 0.23.4
.jshintrc Add futurehostile to jshintrc and sort json file
.npmignore include generate in npm publish because it also gets used for giturl
.travis.yml Merge pull request #796 from nodegit/update-openssl add changelog to 0.4.1 make generic and add fix a few things
LICENSE Updated the license date and binding to latest. Bump version to 0.5.0 Updated to libgit 0.21.3
appveyor.yml build both x86 and x64 on appveyor
package.json Bump libgit2 to 0.23.4


Node bindings to the libgit2 project.

Linux OS X Windows Coverage Dependencies
Coverage Status

Stable: 0.5.0

Have a problem? Come chat with us!


Maintained by

Tim Branyen @tbranyen, John Haley @johnhaley81, Max Korp @maxkorp, and Steve Smith @orderedlist with help from tons of awesome contributors!

Alumni Maintainers

Michael Robinson @codeofinterest, and Nick Kallen @nk

API Documentation.

Getting started.

NodeGit will work on most systems out-of-the-box without any native dependencies.

npm install nodegit

Note: NodeGit will only work on io.js Windows with the iojs binary instead of node.

If you encounter problems while installing, you should try the Building from source instructions.

API examples.

Cloning a repository and reading a file:

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

// Clone a given repository into a specific folder.
clone("", "tmp", null)
  // Look up this known commit.
  .then(function(repo) {
    // Use a known commit sha from this repository.
    return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5");
  // Look up a specific file within that commit.
  .then(function(commit) {
    return commit.getEntry("");
  // Get the blob contents from the file.
  .then(function(entry) {
    // Patch the blob to contain a reference to the entry.
    return entry.getBlob().then(function(blob) {
      blob.entry = entry;
      return blob;
  // Display information about the blob.
  .then(function(blob) {
    // Show the name, sha, and filesize in bytes.
    console.log( + blob.entry.sha() + blob.size() + "b");

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

    // Show the entire file.
  .catch(function(err) { console.log(err); });

Emulating git log:

var open = require("nodegit");

// Open the repository directory.
  // Open the master branch.
  .then(function(repo) {
    return repo.getMasterCommit();
  // Display information about commits on master.
  .then(function(firstCommitOnMaster) {
    // Create a new history event emitter.
    var history = firstCommitOnMaster.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.

For more examples, check the examples/ folder.

Unit tests.

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

npm test

Migrating from old versions.

The bump from 0.1.4 to 0.2.0 was a big one. Many things changed, see here:

This update is wholly and entirely a breaking one, and older versions won't be maintained. For the purpose of migration, perhaps the biggest point to make is that async methods can now use promises, rather than just taking callbacks. Additionally, lots of method and property names have changed.

nw.js (Node-Webkit)

Native compilation for nw.js

A common issue is with NodeGit not functioning properly inside of nw.js applications. Because NodeGit is a native module, it has to be rebuilt for node-webkit using nw-gyp. By default, NodeGit will look in the root package's package.json for an engines property, and within look for a nw.js property (or a node-webkit if the prior isn't found) that holds a specific version of nw.js. The value of this property is what will get passed as the --target argument to nw-gyp configure.

Version incompatibility

Prior to version 0.2.6, NodeGit used nan v1.4.3. As of 0.2.6, NodeGit uses nan v1.5.1 to provide support for io.js. Unfortunately, this breaks some nw.js compatibility. With nw.js 0.12+, the name was changed to nw.js from node-webkit. The alpha currently still breaks with NodeGit due to the nan update, but should be fixed in the final v0.12.0 release. Åpplications using previous versions of node webkit have 2 options: 1) Use an older version (v0.2.4 or earlier) of NodeGit 2) Use npm shrinkwrap to force NodeGit to use nan v1.4.3. Since the binary always recompiles when being used with nw.js, you shouldn't have to do anything else to make sure it works. As of NodeGit v0.2.6, the change to nan v1.4.3 doesn't cause any problems.

Currently, support for nw.js is limited, although we intend to support it better in the future.

Something went wrong with that request. Please try again.