What is .gitignore?

Why Interviewers Ask This

This is a classic screening question for Git & GitHub roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

The .gitignore file tells Git which files or directories to ignore — to not track and not include in commits. Git will not stage or commit ignored files. Syntax: each line is a pattern; # = comment; / at start = relative to .gitignore location; * = wildcard; ** = any level of subdirectories; ! = negate (un-ignore). Examples: node_modules/ — ignore directory; *.log — ignore all .log files; !important.log — except this one; .env — ignore environment secrets; dist/ — ignore build output; *.pyc — Python bytecode; .DS_Store — macOS metadata; *.class — Java compiled files. Scope: .gitignore in the root applies to the whole repo; you can have .gitignore in subdirectories for directory-specific rules. Global gitignore (for your machine): git config --global core.excludesfile ~/.gitignore_global — ignore files like .DS_Store globally. Already tracked files: adding a file to .gitignore does not un-track it if it's already committed — you must run git rm --cached file first. Generate .gitignore for your stack at gitignore.io.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.