.gitignore

A text file of patterns naming untracked files Git should not report or add, such as build output and logs.

In more detail

Each line is a glob pattern: *.log matches by extension, a trailing slash as in build/ matches only directories, a leading slash anchors the pattern to the directory of the .gitignore file, ** matches any number of folders, and ! re-includes a path an earlier rule excluded. A .gitignore in a subdirectory applies from there down and beats the ones above it, and within one file the last matching pattern wins. It never affects files Git already tracks, and it is committed so the whole team ignores the same things.

Examples

*.log
build/
!docs/keep/scratch.md
.venv/
__pycache__/
dist/
.terraform/
*.tfstate
*.tfstate.*
In Terraform: For Terraform it should list the .terraform directory, state files and any variable files holding secrets. The dependency lock file must not be ignored.

Related terms

Taught in

References

Certification courses