# git.js

> Simple api to run git commands from nodejs

Latest version **0.0.25** (published 2015-01-13) · 0 weekly downloads

## Install

```sh
npm install git.js
pnpm add git.js
yarn add git.js
bun add git.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.25 |
| Published | 2015-01-13 |
| First published | 2014-01-06 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| Author | Sergey Todyshev |
| Maintainers | sergeyt |
| Keywords | git, nodejs |

## Links

- npm: https://www.npmjs.com/package/git.js
- Repository: git@github.com:sergeyt/git.js
- Homepage: https://github.com/sergeyt/git.js
- Issues: https://github.com/sergeyt/git.js/issues
- npm.io page: https://npm.io/package/git.js

## Dependencies (7)

- [q](https://npm.io/package/q.md) ~1.0.0
- [async](https://npm.io/package/async.md) ~0.9
- [exequte](https://npm.io/package/exequte.md) 0.0.4
- [parse-diff](https://npm.io/package/parse-diff.md) 0.0.12
- [underscore](https://npm.io/package/underscore.md) ~1.7
- [coffee-script](https://npm.io/package/coffee-script.md) ~1.8
- [underscore.string](https://npm.io/package/underscore.string.md) ~2.4

## Recent versions

- 0.0.25 (latest) — 2015-01-13
- 0.0.24 — 2014-10-05
- 0.0.22 — 2014-10-05
- 0.0.21 — 2014-10-05
- 0.0.20 — 2014-10-05
- 0.0.19 — 2014-01-31
- 0.0.18 — 2014-01-14
- 0.0.17 — 2014-01-14
- 0.0.15 — 2014-01-14
- 0.0.14 — 2014-01-14
- 0.0.13 — 2014-01-14
- 0.0.12 — 2014-01-14
- 0.0.11 — 2014-01-09
- 0.0.10 — 2014-01-07
- 0.0.9 — 2014-01-07
- … 7 more at https://npm.io/package/git.js/versions

## README

# git.js

> Simple api to run git commands from nodejs

[![NPM version](https://badge.fury.io/js/git.js.png)](http://badge.fury.io/js/git.js)
[![Build Status](https://drone.io/github.com/sergeyt/git.js/status.png)](https://drone.io/github.com/sergeyt/git.js/latest)
[![Deps Status](https://david-dm.org/sergeyt/git.js.png)](https://david-dm.org/sergeyt/git.js)

[![NPM](https://nodei.co/npm/git.js.png?downloads=true&stars=true)](https://nodei.co/npm/git.js/)

## API

> Note: most of git.js functions return [javascript promises](http://promises-aplus.github.io/promises-spec/).

First you need to call ```require('git')``` to start using git.js API as in example below:

```javascript
var dir = __dirname; // dir with .git repository
var git = require('git')(dir);
```

Next you could call any of the following functions.

### log command

Use log command to fetch array of commits. Example:

```javascript
git.log().then(function(commits){
	commits.forEach(function(commit){
		console.log(commit.id); // sha-hash
		console.log(commit.author.name);
		console.log(commit.author.email);
		console.log(commit.date);
		console.log(commit.message);
	});
});
```

### status command

Use status command to fetch array of changed files to be committed to git database. Example:

```javascript
git.status().then(function(files){
	files.forEach(function(file){
		console.log(file.status);
		console.log(file.path);
	});
});
```

### diff command

Use diff command to fetch diffs for given files. Example:

```javascript
var files = []; // list of file pathes to get diffs for, all changed files when this list is empty or omitted
git.diff(files).then(function(files){
	files.forEach(function(file){
		console.log(file.from); // path to file from working directory
		console.log(file.lines); // modified lines
		console.log(file.deletions); // number of deletions
		console.log(file.additions); // number of additions
	});
});
```

### other functions

All undocumented functions could be found in the source code.

## TODO

* cover more commands
* unit tests

---
_Source: https://npm.io/package/git.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
