What is the purpose of a .gitignore file?
Options
- To store the access passwords of the repository
- To list files Git must not track, like build output (Correct option)
- To delete files from the repository automatically
- To rename the branches of the repository in bulk
Answer
To list files and folders Git should not track (build output like target/, IDE settings, secrets, logs)
Why
Some files should never be in the repository: compiled output (target/, node_modules/), IDE folders (.idea/), logs, and above all secrets such as .env files with passwords.
List patterns in .gitignore and Git will not stage them. Note: it does not remove files already tracked; use git rm --cached file for those.
If a secret was committed, treat it as leaked: rotate it, since history keeps it.
target/
.idea/
*.log
.envRemember
.gitignore keeps build output and secrets out of the repo.