# GitIgnoreStrategy

Ignores file paths based on the [`.gitignore specification`](https://git-scm.com/docs/gitignore).

Extends: IgnoreStrategy › GitIgnoreStrategy

- Source: [`core/lib/fs/ignore.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/core/lib/fs/ignore.ts#L157)
- Type last changed: v2.217.0 · 25 Sep 2025

## Example

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
const gitIgnoreStrategy = new cdk.GitIgnoreStrategy('absoluteRootPath', ['patterns']);
```

## Initializer

```ts
new GitIgnoreStrategy(absoluteRootPath: string, patterns: string[])
```

## Methods

- `add(pattern: string): void` — Adds another pattern.

- `completelyIgnores(absoluteDirectoryPath: string): boolean` — Determines whether a given directory path should be ignored and have all of its children ignored.

  **Parameters**

  - `absoluteDirectoryPath` — absolute directory path to be assessed against the pattern.

  **Returns:** `true` if the directory and all of its children should be ignored

- `docker(absoluteRootPath: string, patterns: string[]): DockerIgnoreStrategy` (static) — Ignores file paths based on the [`.dockerignore specification`](https://docs.docker.com/engine/reference/builder/#dockerignore-file).

  **Parameters**

  - `absoluteRootPath` — the absolute path to the root directory of the paths to be considered.

  **Returns:** `DockerIgnorePattern` associated with the given patterns.

- `fromCopyOptions(options: CopyOptions, absoluteRootPath: string): IgnoreStrategy` (static) — Creates an IgnoreStrategy based on the `ignoreMode` and `exclude` in a `CopyOptions`.

  **Parameters**

  - `options` — the `CopyOptions` to create the `IgnoreStrategy` from.
  - `absoluteRootPath` — the absolute path to the root directory of the paths to be considered.

  **Returns:** `IgnoreStrategy` based on the `CopyOptions`

- `git(absoluteRootPath: string, patterns: string[]): GitIgnoreStrategy // chainable` (static) — Ignores file paths based on the [`.gitignore specification`](https://git-scm.com/docs/gitignore).

  **Parameters**

  - `absoluteRootPath` — the absolute path to the root directory of the paths to be considered.

  **Returns:** `GitIgnorePattern` associated with the given patterns.

- `glob(absoluteRootPath: string, patterns: string[]): GlobIgnoreStrategy` (static) — Ignores file paths based on simple glob patterns.

  **Parameters**

  - `absoluteRootPath` — the absolute path to the root directory of the paths to be considered.

  **Returns:** `GlobIgnorePattern` associated with the given patterns.

- `ignores(absoluteFilePath: string): boolean` — Determines whether a given file path should be ignored or not.

  **Parameters**

  - `absoluteFilePath` — absolute file path to be assessed against the pattern.

  **Returns:** `true` if the file should be ignored
