Install NodeGit

NodeGit can be quickly and painlessly installed via NPM. For more comprehensive installation techniques, check out the Install Guides.

npm install nodegit

Compatibility

Native Shells

Operating systems

Node support


Getting Started

You simply need to require NodeGit in your project to start using it.

var Git = require("nodegit");

Clone a Repository

Let’s learn how to clone a repository. Create a file named clone.js, and add the following code:

var Git = require("nodegit");

Git.Clone("https://github.com/nodegit/nodegit", "nodegit").then(function(repository) {
  // Work with the repository object here.
});

This will clone our repository into a folder named nodegit.

Open a Repository

Let’s learn how to open a repository. Create a file named open.js, and add the following code:

var Git = require("nodegit");

var getMostRecentCommit = function(repository) {
  return repository.getBranchCommit("master");
};

var getCommitMessage = function(commit) {
  return commit.message();
};

Git.Repository.open("nodegit")
  .then(getMostRecentCommit)
  .then(getCommitMessage)
  .then(function(message) {
    console.log(message);
  });

This will open our cloned repository and read out the latest commit’s message from master.

Have a problem? Come chat with us!

Visit slack.libgit2.org to sign up, then join us in #nodegit.


Brought to you by

NodeGit is brought to you by the work of many contributors all over the globe. We are proud to be sponsored by the following companies to continue work on making NodeGit one of the best native node modules around!