Every time you run your tests, a bunch of files get generated — reports, screenshots, compiled classes, log files. If you commit these to Git, your repo becomes a bloated mess. Your PRs show 200 changed files when you only changed 2 test files. Your colleagues hate you.
.gitignore tells Git: "Ignore these files. Don't track them. Don't show them in git status." You create this file once, commit it, and never worry about accidentally committing junk again.
| Pattern | Why Ignore |
|---|---|
| target/ | Maven build output — compiled classes, reports. Generated fresh every build. |
| build/ | Gradle build output — same idea as target/ |
| .idea/ | IntelliJ IDEA settings — personal to each developer's machine |
| .vscode/ | VS Code workspace settings |
| *.iml | IntelliJ module files |
| test-output/ | TestNG output — generated every test run |
| allure-results/ | Allure raw data — generated fresh each run |
| allure-report/ | Generated Allure HTML report |
| screenshots/ | Failure screenshots from test runs |
| *.log | Log files — can be huge, different every run |
| *.class | Compiled Java bytecode — regenerated on build |
| .env | Environment variables — may contain passwords and API keys |
| .DS_Store | macOS file — irrelevant to the project |
| node_modules/ | npm dependencies — for JS/TS projects |
# ========= .gitignore for Selenium + Java + Maven =========
# Build output
target/
build/
out/
# IDE files (personal to each dev)
.idea/
.vscode/
*.iml
*.ipr
*.iws
.classpath
.project
.settings/
# Test output and reports (generated each run)
test-output/
allure-results/
allure-report/
screenshots/
extent-report.html
# Compiled files
*.class
*.jar
*.war
# Logs
*.log
logs/
# OS files
.DS_Store
Thumbs.db
# Secrets — NEVER commit these
.env
*.properties
!src/test/resources/*.properties
# Node (if using JS test tools)
node_modules/
package-lock.jsonCreate .gitignore BEFORE your first commit. If you already committed files that should be ignored, remove them from tracking: git rm -r --cached target/ then commit. The files stay on your disk but Git stops tracking them.
# Oops, I already committed target/ — fix it:
git rm -r --cached target/
git commit -m "Remove target folder from Git tracking"
# Now target/ is ignored going forwardNEVER commit .env files, passwords, API keys, or database credentials. Even if you delete them later, they stay in Git history forever. Anyone who clones the repo can find them. This has caused real security breaches at real companies.
Q: What do you put in .gitignore for a Selenium project?
A: We ignore build output (target/, build/), IDE files (.idea/, .vscode/, *.iml), test artifacts (test-output/, allure-results/, screenshots/), compiled files (*.class), logs (*.log), OS files (.DS_Store), and sensitive files (.env). These files are either generated during each test run, specific to each developer's machine, or contain sensitive information. Committing them would bloat the repo and cause unnecessary merge conflicts.
Key Point: Create .gitignore on day one. Never commit build output, IDE files, test reports, or secrets.