How do the patterns in a .gitignore file work?
Each line is a pattern. * matches any characters except a slash, a trailing slash matches directories, ** matches nested directories, ! negates a pattern, and
Explain it simply
A .gitignore is a list of name tags the doorman should turn away. Patterns are like filename wildcards.
*.log ignores every log file. node_modules/ ignores that folder only. /build with a leading slash anchors it to the repo root. **/temp matches a temp folder at any depth. !important.log re-includes a file that an earlier rule ignored, but it cannot re-include a file whose parent folder is ignored. Later lines override earlier ones.
Example
# dependencies
node_modules/
# build output at repo root
/dist
# logs, but keep one
*.log
!keep.log
# env files
.env*What to say in the interview
"Patterns work like wildcards: for any characters, a trailing slash for directories, a leading slash to anchor at the root, * for any depth, and ! to negate. Later rules win, and I cannot re-include a file inside an ignored folder."