.gitignore Template for Web Projects

Copy this .gitignore to the root of your web project (PHP, JavaScript or any other) and remove the lines you do not need.

# Dependencies
node_modules/
vendor/

# Environment and secrets
.env
.env.*
!.env.example
*.pem

# Logs and temporary files
*.log
*.tmp
*.cache

# Build output
dist/
build/

# System files
.DS_Store
Thumbs.db

# Editor files
.idea/
.vscode/
*.swp

Test the template

Terminal output

$ mkdir shop
$ cd shop
$ git init -q
$ cp ../.gitignore .
$ echo "x" > debug.log
$ echo "SECRET=1" > .env
$ echo "SECRET=" > .env.example
$ mkdir node_modules
$ echo "x" > node_modules/pkg.js
$ echo "<h1>Hi</h1>" > index.html
$ git status -s
?? .env.example
?? .gitignore
?? index.html

How it works

  • node_modules/ ignores the full folder.
  • .env.* ignores all env variants, and the line !.env.example keeps the example file, which has no real secrets.
  • Patterns like *.log match files in any folder.
Note: A .gitignore does not remove files that are already tracked. See Git Ignore for how to untrack them.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.