# GitIgnoreStrategy

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

Extends: [IgnoreStrategy](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IgnoreStrategy.html) › GitIgnoreStrategy
Obtainable from: [IgnoreStrategy.git](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IgnoreStrategy.html#git)

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

## Example

TypeScript:

```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 = cdk.GitIgnoreStrategy.fromCopyOptions({
  exclude: ['exclude'],
  follow: cdk.SymlinkFollowMode.NEVER,
  ignoreMode: cdk.IgnoreMode.GLOB,
}, 'absoluteRootPath');
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk

git_ignore_strategy = cdk.GitIgnoreStrategy.from_copy_options(cdk.CopyOptions(
    exclude=["exclude"],
    follow=cdk.SymlinkFollowMode.NEVER,
    ignore_mode=cdk.IgnoreMode.GLOB
), "absoluteRootPath")
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;

IgnoreStrategy gitIgnoreStrategy = GitIgnoreStrategy.fromCopyOptions(CopyOptions.builder()
        .exclude(List.of("exclude"))
        .follow(SymlinkFollowMode.NEVER)
        .ignoreMode(IgnoreMode.GLOB)
        .build(), "absoluteRootPath");
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;

var gitIgnoreStrategy = GitIgnoreStrategy.FromCopyOptions(new CopyOptions {
    Exclude = new [] { "exclude" },
    Follow = SymlinkFollowMode.NEVER,
    IgnoreMode = IgnoreMode.GLOB
}, "absoluteRootPath");
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

gitIgnoreStrategy := cdk.GitIgnoreStrategy_FromCopyOptions(&CopyOptions{
	Exclude: []*string{
		jsii.String("exclude"),
	},
	Follow: cdk.SymlinkFollowMode_NEVER,
	IgnoreMode: cdk.IgnoreMode_GLOB,
}, jsii.String("absoluteRootPath"))
```

## Initializer

TypeScript:

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

Python:

```python
GitIgnoreStrategy(absolute_root_path: str, patterns: typing.List[str])
```

Java:

```java
new GitIgnoreStrategy(String absoluteRootPath, List<String> patterns)
```

C# / .NET:

```csharp
new GitIgnoreStrategy(string absoluteRootPath, string[] patterns)
```

Golang:

```go
NewGitIgnoreStrategy(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

- `none(): IgnoreStrategy` (static) — Return an IgnoreStrategy that does not ignore any files.
