What is .gitignore?
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.