How do I ignore folders? folder/ versus /folder/

Use /logs/ for the logs directory beside the root .gitignore, or logs/ for directories with that name at any depth below it. Choose the scope before adding rules.

1. Ignore a directory at the project root

Put this rule in the root .gitignore. It excludes logs/app.log and everything else under the root logs directory, while packages/api/logs/app.log remains eligible for tracking. The leading / anchors the pattern to the directory containing this .gitignore.

/logs/

2. Ignore matching directories at any depth

Use this alternative when every directory named logs should be ignored. A trailing / restricts the rule to directories; logs without that slash can also match a file named logs.

Patterns in a nested .gitignore are relative to that file, so /logs/ there refers to its local logs directory, not the repository root. A path such as packages/api/logs/ already has an internal slash and is relative to the .gitignore location.

logs/

How do I ignore file extensions? Using * and **

3. Verify the scope

With both sample files present and untracked, run this from the repository root. Compare the rule source and pattern:

git check-ignore -v -- logs/app.log packages/api/logs/app.log

With /logs/, only the root path should match. With logs/, both paths should match. Other rules may change the result. Already tracked files require separate handling; to retain an exception inside an ignored directory, see the exception-rule article.

How do I ignore files Git already tracks?

For exact behavior and further details, consult the official references: Git documentation · git check-ignore documentation