Git Ignoring Files and Folders Ignoring files in subfolders (Multiple gitignore files)


Example

Suppose you have a repository structure like this:

examples/
    output.log
src/
    <files not shown>
    output.log
README.md

output.log in the examples directory is valid and required for the project to gather an understanding while the one beneath src/ is created while debugging and should not be in the history or part of the repository.

There are two ways to ignore this file. You can place an absolute path into the .gitignore file at the root of the working directory:

# /.gitignore
src/output.log

Alternatively, you can create a .gitignore file in the src/ directory and ignore the file that is relative to this .gitignore:

# /src/.gitignore
output.log