# git-cli

> Simple CLI like git interface for NodeJS

Latest version **0.11.0** (published 2018-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install git-cli
pnpm add git-cli
yarn add git-cli
bun add git-cli
```

## 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.11.0 |
| Published | 2018-09-22 |
| First published | 2014-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 28.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Daniel Perez |
| Maintainers | tuvistavie |
| Keywords | git |

## Links

- npm: https://www.npmjs.com/package/git-cli
- Repository: https://github.com/tuvistavie/node-git-cli
- Issues: https://github.com/tuvistavie/node-git-cli/issues
- npm.io page: https://npm.io/package/git-cli

## Dependencies (2)

- [fs-extra](https://npm.io/package/fs-extra.md) ^0.9.1
- [underscore](https://npm.io/package/underscore.md) ^1.6.0

## Recent versions

- 0.11.0 (latest) — 2018-09-22
- 0.10.0 — 2016-05-03
- 0.9.1 — 2016-04-12
- 0.9.0 — 2015-11-14
- 0.8.3 — 2015-05-11
- 0.8.2 — 2014-09-16
- 0.8.1 — 2014-09-16
- 0.8.0 — 2014-08-27
- 0.7.0 — 2014-08-26
- 0.6.2 — 2014-08-20
- 0.6.1 — 2014-08-20
- 0.6.0 — 2014-08-15
- 0.5.0 — 2014-08-13
- 0.4.0 — 2014-08-13
- 0.3.1 — 2014-08-13
- … 10 more at https://npm.io/package/git-cli/versions

## README

# node-git-cli [![Build Status][travis-img]][travis-build] [![Coverage Status][coveralls]][coveralls-img]

A simple git interface for NodeJS.
It is not intended to replace projects such as 
[nodegit](https://github.com/nodegit/nodegit) but 
rather to provide a light weight solution close to 
the git command line for simple use cases.

## Installation

Just run

```
$ npm install git-cli
```

## Usage

The usage is pretty straightforward, here is a sample code.

```coffee
Repository = require('git-cli').Repository
fs = require 'fs'

Repository.clone 'https://github.com/tuvistavie/node-git-cli', 'git-cli', (err, repo) ->
  repo.log (err, logs) ->
    console.log logs[0].subject
    repo.showRemote 'origin', (err, remote) ->
      console.log remote.fetchUrl

      fs.writeFileSync "#{repo.workingDir()}/newFile", 'foobar'
      repo.status (err, status) ->
        console.log status[0].path
        console.log status[0].tracked

        repo.add (err) ->
          repo.status (err, status) ->
            console.log status[0].path
            console.log status[0].tracked

            repo.commit 'added newFile', (err) ->
              repo.log (err, logs) ->
                console.log logs[0].subject

              repo.push (err) ->
                console.log 'pushed to remote'
```

From version 0.10, all functions still take a callback, but also return promises,
so you can rewrite the above as follow:

```javascript
const Repository = require('git-cli').Repository
const fs = require('fs')

Repository.clone('https://github.com/tuvistavie/node-git-cli', 'git-cli')
  .then(repo => {
    return repo.log()
      .then(logs => {
        console.log(logs[0].subject)
        return repo.showRemote('origin')
    }).then(remote => {
        console.log(remote.fetchUrl)
        fs.writeFileSync("#{repo.workingDir()}/newFile", 'foobar')
        return repo.status()
    }).then(status => {
        console.log(status[0].path)
        console.log(status[0].tracked)
        return repo.add()
    }).then(() => repo.status())
      .then(status => {
        console.log status[0].path
        console.log status[0].tracked
        return repo.commit('added newFile')
    }).then(() => repo.log())
      .then(logs => {
        console.log(logs[0].subject)
        return repo.push()
    }).then(() => console.log('pushed' to remote))
  }).catch(e => console.log(e))
```

Checkout out [the tests](test/repository-test.coffee) for more examples.

[travis-build]: https://travis-ci.org/tuvistavie/node-git-cli
[travis-img]: https://travis-ci.org/tuvistavie/node-git-cli.svg?branch=master
[coveralls]: https://coveralls.io/repos/tuvistavie/node-git-cli/badge.png?branch=master
[coveralls-img]: https://coveralls.io/r/tuvistavie/node-git-cli?branch=master

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