🚫 .gitignore: Keep the Right Files Out of Git
gitignore: Keep the Right Files Out of: .gitignore works like the "do not publish" stamp a legal team puts on internal draft documents before sending a contract packet to the cli
.gitignore works like the "do not publish" stamp a legal team puts on internal draft documents before sending a contract packet to the client: the drafts still exist in the office filing cabinet, they just never leave the building. The critical "why" question here is: if a file is already in the repository, does adding it to .gitignore make it disappear from Git history? No — .gitignore only blocks untracked files from being accidentally staged; anything already committed stays in history forever until explicitly purged. Java analogy: Maven's default .gitignore excludes the `target/` directory the same reason no one commits compiled `.class` files — the build tool regenerates them deterministically, so shipping the source (pom.xml + src/) is sufficient, and committing target/ would bloat the repository by megabytes on every build. For QA automation this matters when someone accidentally commits a Playwright `test-results/` folder with video recordings — clone time triples overnight and sensitive test data about production URLs leaks into the public repository history.
Purpose: why does .gitignore exist?
The .gitignore file tells Git which files and folders to never track: build output, downloaded dependencies, IDE settings, OS junk files, logs, and secrets. It is a shared, committed file, so the whole team ignores the same things automatically without remembering it by hand. Java analogy: a Maven project never commits the target folder with compiled class files and generated jars, only pom.xml and source files are version-controlled. The same idea applies to the node_modules folder in a JavaScript project — you commit the recipe, package.json, not the generated result.
First decision: commit it or ignore it?
gitignore-create-and-match
Create a .gitignore and watch it filter files
Watch how Git automatically skips matching files and folders from git status once a pattern exists.
How to create it: Git Bash, IntelliJ and other IDEs
Where it goes: almost always at the project root, right next to package.json or pom.xml. Git also supports a .gitignore file inside any subfolder — rules in a nested .gitignore only apply to that folder and below, and the closest .gitignore wins for a given file. For ignore rules that are personal and should never be shared with the team, use a global ignore file instead, configured once with git config --global core.excludesFile, or the repository-local file at .git/info/exclude, which is never committed.
What is inside: pattern syntax
A realistic .gitignore for a QA automation project
What Do node_modules/ and .env* Actually Tell Git?
The trailing / in node_modules/…
The trailing / in node_modules/ MARKS it as a FOLDER — Git IGNORES it EVERYWHERE it finds a folder with this name, no matter how DEEP.