npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gitjs

v0.0.6

Published

A wrapper for running git commands

Readme

gitjs

A Node.js module for interacting with git repositories.

Install

$ npm install gitjs

Usage

var git = require('gitjs');

git.open ( repoPath[, autoCreate = false], callback )

Opens a git repository so git commands can be run. If the autoCreate parameter is given and is truthy, then the open function will init a new repository if one is not already in the given directory.

git.open('/path/to/repo', function(err, repo) {
	
	// ...
	
});

git.init ( repoPath, callback )

Intializes a new git repo in the given directory.

git.init('/path/to/project', function(err, repo) {
	
	// ...
	
});

Repo::run ( cmd[, args], callback )

Runs a git command in the repository. If an args array is given, it will be used to populate ? placeholders in the command. As an example, on the command line you would create a new branch like so:

$ git branch foo

The same could be done with gitjs like this:

repo.run('branch foo', function(err, stdout, stderr) {
	
	// ...
	
});

Also, you could make the branch name variable using the args parameter like this:

function createBranch(repo, branchName) {
	repo.run('branch ?', [branchName], function(err, stdout, stderr) {
		
		// ...
		
	});
}

Repo::add ( <String|Array> files, callback )

Stages files to be committed.

// All of the following are acceptable formats for files

repo.add('*', function(err, stdout, stderr) {
	
	// ...
	
});

repo.add('.', ...);

repo.add('foo.txt bar.txt', ...);

repo.add([ 'baz.txt', 'foo.html', 'bar.css' ], ...);

Repo::commit ( message, callback )

Commits the repository changes.

repo.commit('Changed foo.txt', function(err, stdout, stderr) {
	
	// ...
	
});

Repo::commitAll ( message, callback )

Commits the repository changes with a git commit -a.

Repo::cloneTo ( target, callback )

Does a local clone of the repository to the given target path.

repo.cloneTo('/path/to/clone', function(err, stdout, stderr) {
	
	// ...
	
});

Repo::clean ( dirs, callback )

Runs a git clean. If the dirs parameter is truthy, a -d flag will be used.

Repo::listBranches ([ giveObjs = false,] callback )

Gets an array of branch names for the repository. If the giveObjs parameter is given and is truthy, objects about the branches will be given instead of just names.

repo.listBranches(function(err, branches) {
	
	console.log(branches[0]);  // "master"
	
});

repo.listBranches(true, function(err, branches) {
	
	console.log(branches[0]);  // { name: "master", isCurrent: true }
	
});

Repo::currentBranch ( callback )

Gets the name of the current branch.

repo.currentBranch(function(err, branch) {
	
	console.log(branch);  // "master"
	
});

Repo::listRemotes ( callback )

Gets the names of all remotes for the repository.

repo.listRemotes(function(err, remotes) {
	
	console.log(remotes[0]);  // "origin"
	
});

Repo::remoteExists ( remote, callback)

Determines if a given remote exists.

repo.remoteExists('origin', function(err, exists) {
	
	console.log(exists);  // true
	
});

Repo::createBranch ( name, callback )

Creates a new branch.

repo.createBranch('dev', function(err, stdout, stderr) {
	
	// ...
	
});

Repo::deleteBranch ( name[, force = false], callback )

Deletes a branch from the repository. If the force parameter is given and is truthy, the -f flag will be given, forcing the branch to be deleted, even if it has unmerged changes.

Repo::checkout ( name, callback )

Checks out the given branch.

repo.checkout('master', function(err, stdout, stderr) {
	
	// ...
	
});

Repo::status ( callback )

Runs a git status --porcelain -z command and parses the results into an array of files and the changes. Each value in the array is an object with the file name and the x and y change flags as defined in the git man pages.

{
	x: 'M', y: ' ',
	file: 'foo.txt'
}

Repo::push ( callback )

Pushing commits to git

repo.push(function(err, stdout, stderr) {
	
	// ...
	
});