# git-lib

> A github library for multiple package uses

Latest version **1.6.0** (published 2015-08-11) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2015-08-11 |
| First published | 2015-08-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Joey Sham |
| Maintainers | joeyism |
| Keywords | git, add, commit, revert, show, modified, files, current, delete, checkout, local, remote, branch |

## Links

- npm: https://www.npmjs.com/package/git-lib
- Repository: https://github.com/joeyism/node-git-lib
- Homepage: https://github.com/joeyism/node-git-lib#readme
- Issues: https://github.com/joeyism/node-git-lib/issues
- npm.io page: https://npm.io/package/git-lib

## Dependencies (5)

- [async](https://npm.io/package/async.md) ^1.4.2
- [xcept](https://npm.io/package/xcept.md) ^1.0.0
- [colors](https://npm.io/package/colors.md) ^1.1.2
- [lodash](https://npm.io/package/lodash.md) ^3.10.1
- [promise](https://npm.io/package/promise.md) ^7.0.4

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.6.0 (latest) — 2015-08-11
- 1.5.0 — 2015-08-11
- 1.4.1 — 2015-08-10
- 1.4.0 — 2015-08-10
- 1.3.2 — 2015-08-07
- 1.3.1 — 2015-08-07
- 1.3.0 — 2015-08-07
- 1.2.4 — 2015-08-06
- 1.2.3 — 2015-08-06
- 1.2.2 — 2015-08-06
- 1.2.1 — 2015-08-05
- 1.2.0 — 2015-08-05
- 1.1.0 — 2015-08-05
- 1.0.0 — 2015-08-05

## README

# git-lib

[![Build Status](https://travis-ci.org/joeyism/node-git-lib.svg?branch=master)](https://travis-ci.org/joeyism/node-git-lib)

A library that contains different methods to be consumed by a node module

## Install
To install, simply run

    > npm install --save git-lib

## Use
To use, require it by
    
    var git = require("git-lib");

## Methods
* [`haveFilesToCommit`](#havefilestocommit)
* [`add`](#add)
* [`getCurrentBranch`](#getcurrentbranch)
* [`showFilesAdded`](#showfilesadded)
* [`showFilesModified`](#showfilesmodified)
* [`commit`](#commit)
* [`revert`](#revert)
* [`isGit`](#isgit)
* [`isGitSync`](#isgitsync)
* [`getFilesCached`](#showfilescached)
* [`getBranches`](#getbranches) both remote and local
* [`newBranch`](#newbranch)
* [`checkout`](#checkout) both remote and local
* [`deleteBranch`](#deletebranch)
* [`deleteBranches`](#deletebranches)


### haveFilesToCommit
Resolves if current directory has files to commit, throws if it doesn't
    
    git.haveFilesToCommit().then(function(){
        /** there are files to commit **/
    }).catch(function(err){
        if (err === "There are no files to commit"){
            /** there are no files to commit **/
        }
        else {
            /** some error has occured **/
        }
    });

### add
Attempts to *git add* a file

    git.add("example.file").then(function(){
        /** successfully added **/
    }).catch(function(err){
        /** unsuccessful **/
    });
    
### getCurrentBranch
Gets the name of the directory's current branch

    git.getCurrentBranch().then(function(branchname){
        /** branchname has the name of current branch **/
    }).catch(function(err){
        /** throws an error **/
    });
    
### showFilesAdded
Show files that has already been added

    git.showFilesAdded().then(function(filesAdded){
        /** filesAdded shows, in a string, a list of files added **/
    }).catch(function(err){
        /** throws an error**/
    });
    
### showFilesModified
Show files in current directory that has been modified (and probably needs to be commited)

    git.showFilesModified().then(function(modifiedFiles){
        /** modifiedFiles is an array of files that has been modified **/
    }).catch(function(err){
        /** throws an error **/
    });
    
### commit
Commits with a string of message and a string of options

    git.commmit("message to commit", "--force").then(function(){
        /** commit successful **/
    }).catch(function(err){
        /** throws an error **/
    });
    
### revert
Takes an array of files, or a string of only one file, and reverts them

    git.revert(["file1","file2"]).then(function(){
        /** successfully reverted **/
    }).catch(function(err){
        /** throws an error **/
    });

### isGit
Determines if current directory has git initialized

    git.isGit().then(function(){
        /** has git initialized **/
    }).catch(function(err){
        /** doesn't have git initialized, and err displays that **/
    });

### isGitSync
A synchronous version of [`isGit`](#isgit), so it can be used in an *if* statement

    if (git.isGitSync()){
        /** has git initialized **/
    }
    else {
        /** doesn't have git initialized **/
    }

### getFilesCached
Show files that are cached, which are also files that are added

    git.getFilesCached().then(function(files){
        /** files is an array list of files that has been added **/
    }).catch(function(err){
        /** throws an error **/
    });

### getBranches
**Local**

Returns all local branches for the current git repository

    git.getBranches.local().then(function(branches){
        /** branches is an array of local branches **/  
    }).catch(function(error){
        /** throws an error **/
    });

**all**

Returns all branches, including remote, for the current git repository

    git.getBranches.all().then(function(branches){
        /** branches is an array of all branches **/  
    }).catch(function(error){
        /** throws an error **/
    });

### checkout
Changes into branch *thisBranch*, where *thisBranch* is passed into the function

    git.checkout("thisBranch").then(function(){
        /** successfully checked out into branch *thisBranch* **/
    }).catch(function(err){
        /** throws an error **/
    });

### newBranch
Creates new branch *newBranch*, where *newBranch* is passed into the function

    git.newBranch("newBranch").then(function(){
        /** new branch *newBranch* was successfully created **/
    }).catch(function(err){
        /** throws an error **/
    });

### deleteBranch
Deletes branch *thisbranch*, where *thisbranch* is passed into the function

    git.deleteBranch("thisbranch").then(function(){
        /** new branch *thisbranch* was successfully deleted**/
    }).catch(function(err){
        /** throws an error **/
    });

### deleteBranches
Delete multiple branches, using [`deleteBranch`](#deletebranch). The array passed into the function is the array of a list of branches to delete

    git.deleteBranches(/** array of branches name **/).then(function(result){
        /** result = { success: [ all the successfully deleted branches ], failure: [ all the branches that failed to be deleted ] } **/
    });

## Versions
**1.6.0**
* Added deleteBranches

**1.5.0**
* Added deleteBranch

**1.4.0**
* Updated to include methods for checkout-cli

**1.3.1**
* changed showFilesCached to getFilesCached

**1.3.0**
* Added showFilesCached

**1.2.3**
* fixed both isGit

**1.2.2**
* Added error output with isGit

**1.2.1**
* Fixed README bugs

**1.2.0**
* Updated with isGit and isGitSync

**1.1.0**
* Added README
* Added showFilesAdded

**1.0.0**
* First publish

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