# @netlify/git-utils

> Utility for dealing with modified, created, deleted files since a git commit

Latest version **7.1.1** (published 2026-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @netlify/git-utils
pnpm add @netlify/git-utils
yarn add @netlify/git-utils
bun add @netlify/git-utils
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.1.1 |
| Published | 2026-08-25 |
| First published | 2020-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.12.0 |
| Dependencies | 3 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 259 |
| Author | Netlify Inc. |
| Maintainers | netlify-bot, mikewen, youvalv, serhalp-netlify, mlgualtieri-gatsby |
| Keywords | nodejs, javascript, windows, macos, linux, shell, bash, build, terminal, deployment, es6, serverless, continuous-integration, continuous-delivery, ci, continuous-deployment, plugins, continuous-testing, netlify-plugin, netlify |

## Links

- npm: https://www.npmjs.com/package/@netlify/git-utils
- Repository: https://github.com/netlify/build
- Issues: https://github.com/netlify/build/issues
- npm.io page: https://npm.io/package/@netlify/git-utils

## Dependencies (3)

- [tinyexec](https://npm.io/package/tinyexec.md) ^1.3.0
- [micromatch](https://npm.io/package/micromatch.md) ^4.0.2
- [micro-memoize](https://npm.io/package/micro-memoize.md) ^5.1.1

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 7.1.1 (latest) — 2026-08-25
- 4.1.3-rc (rc) — 2022-09-23
- 7.1.0 — 2026-07-17
- 7.0.0 — 2026-06-16
- 6.0.4 — 2026-02-25
- 6.0.3 — 2025-12-19
- 6.0.2 — 2025-05-29
- 6.0.1 — 2025-05-20
- 6.0.0 — 2025-05-14
- 5.2.0 — 2024-12-11
- 5.1.1 — 2023-03-13
- 5.1.0 — 2022-12-13
- 5.0.2 — 2022-11-17
- 5.0.1 — 2022-10-18
- 5.0.0 — 2022-10-11
- … 29 more at https://npm.io/package/@netlify/git-utils/versions

## README

[![Coverage Status](https://codecov.io/gh/netlify/build/branch/main/graph/badge.svg)](https://codecov.io/gh/netlify/build)
[![Build](https://github.com/netlify/build/workflows/Build/badge.svg)](https://github.com/netlify/build/actions)

# Git Utility

Utility for dealing with modified, created, deleted files since a git commit.

## Usage

```js
/* Export the Netlify Plugin */
export const onPreBuild = function ({ utils }) {
  const { git } = utils

  /* Do stuff if files modified */
  if (git.modifiedFiles.length !== 0) {
    console.log('Modified files:', git.modifiedFiles)
  }

  /* Do stuff only if html code edited */
  const htmlFiles = git.fileMatch('**/*.html')
  console.log('html files git info:', htmlFiles)

  if (htmlFiles.edited.length !== 0) {
    console.log('>> Run thing because HTML has changed\n')
  }
  //
  /* Do stuff only if markdown files edited */
  const markdownFiles = git.fileMatch('**/*.md')
  console.log('markdown files git info:', markdownFiles)

  if (markdownFiles.modified.length !== 0) {
    console.log('>> Run thing because Markdown files have been created/changed/deleted\n')
  }

  /* Do stuff only if css files edited */
  const cssFiles = git.fileMatch('**/*.css')
  if (cssFiles.deleted.length !== 0) {
    console.log('>> Run thing because css files have been deleted\n')
    console.log(cssFiles)
  }
}
```

## API

The `git` util includes the following signature.

```js
export const onPreBuild = function ({ utils }) {
  console.log(utils.git)
  // {
  // fileMatch: [Function], <-- Lookup function. See below
  // modifiedFiles: [ Array of all modified files ],
  // createdFiles: [ Array of all created files ],
  // deletedFiles: [ Array of all deleted files ],
  // commits: [ Array of commits with details ],
  // linesOfCode: [AsyncFunction: linesOfCode] <-- how many lines of code have changed
  // }
  //
}
```

`git.fileMatch()` is a glob matcher function to detect the git status of a pattern of files.

```js
export const onPreBuild = function ({ utils }) {
  const cssFiles = utils.git.fileMatch('**/*.css')
  console.log('cssFiles', cssFiles)
  // {
  // modified: [ 'just-changed.css', 'just-changed-two.css' ],
  // created: [ 'just-added.css' ],
  // deleted: [ 'just-deleted.css' ],
  // edited: [ 'just-changed.css', 'just-changed-two.css', 'just-added.css', 'just-deleted.css' ]
  // }
  //
}
```

## Prior art

This was originally found in [danger.js](https://danger.systems/js/) and extracted into this utility.

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