https://github.com/pierredemailly/node-git
Git API for node.js
https://github.com/pierredemailly/node-git
git nodejs
Last synced: 2 months ago
JSON representation
Git API for node.js
- Host: GitHub
- URL: https://github.com/pierredemailly/node-git
- Owner: PierreDemailly
- License: isc
- Created: 2022-06-24T21:47:54.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-10T15:39:29.000Z (about 1 year ago)
- Last Synced: 2025-03-15T01:19:38.522Z (3 months ago)
- Topics: git, nodejs
- Language: JavaScript
- Homepage: https://pierredemailly.github.io/node-git/
- Size: 782 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
> Simple Git API for Node.js (ESM).
[](#contributors-)
[](https://npmjs.com/package/@pierred/node-git)
[](https://github.com/PierreDemailly/node-git/commits/main)## Installation
```
npm i @pierred/node-git
```## API
### `changesCount()`
Get the count of changes.It does include changes that have been staged, which haven't.
It does not include changes that are untracked.
```ts
changesCount(): Promise
```### `stagedCount()`
Get the count of changes that have been staged.
```ts
stagedCount(): Promise
```### `commit(message[, options])`
Create a commit given one or multiple commit message(s).```ts
commit(message: string | string[], options?: { skipHooks: boolean }): Promise
```
Example usage:```ts
await commit("My Commit"); // execute `git commit -m "My Commit"`.
await commit(["My Commit", "My Second Commit"]); // execute `git commit -m "My Commit" -m "My Second Commit"`.
```### `indexAll(options)`
Add current changes to the git staging area.```ts
indexAll(options?: IndexAllOptions): Promise
```
### `indexAllCurrentDirectory(options)`
Add current changes of the current working directory to the git staging area.```ts
indexAllCurrentDirectory(options?: indexAllCurrentDirectoryOptions): Promise
```
This method should not be used with Git V2.x without ignoreRemovals: true, because Git V2.x does include deleted files
by default. Git V1.x side, it doesn't support --ignore-removal flag, deleted files are
omitted as expected behavior.### `indexFileOrDirectory(fileOrDirectory)`
Add standalone file or directory to the git staging area.```ts
indexFileOrDirectory(fileOrDirectory: string): Promise
```### `indexFilesOrDirectories(filesOrDirectories)`
Add multiple files or directories to the git staging area.```ts
indexFilesOrDirectories(filesOrDirectories: string[]): Promise
```
### `logs()`
Get the list of all commits for the current branch.```ts
logs(): Promise
```### `push()`
Push to remote.```ts
push(): Promise
```### `restoreFile(file)`
Remove given file from the git staging area.```ts
restoreFile(file: string): Promise
```### `currentBranch()`
Retrieve current branch name.```ts
currentBranch(): Promise
```### `init()`
Initialize a git repository.
If git is already initialized, it will prompt for a confirmation.```ts
init(): Promise;
```### `currentAuthor()`
Get the current author to the format `name ` (based on Git configuration).```ts
currentAuthor(): Promise;
```## Types
### IndexAllOptions
```ts
interface IndexAllOptions {
omitNewFiles: boolean;
}
```
Whether omit to index new files.
Setting it to true will execute git add -u.### indexAllCurrentDirectoryOptions
```ts
interface indexAllCurrentDirectoryOptions {
ignoreRemovals: boolean;
}
```
Whether omit to index deleted files.
Setting it to true will execute git add . --ignore-removal.### CommitMergeResult
```ts
interface CommitMergeResult {
from: string;
to: string;
}
```
Represents the result of a merge commit.### CommitAuthor
```ts
interface CommitAuthor {
name: string;
email: string;
}
```
Represents a commit author: name & email.### Commit
```ts
interface Commit {
commit: string,
merged: null | CommitMergeResult,
author: CommitAuthor,
date: string,
message: string[]
}
```
Represent a commit.## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!