What is a .gitignore file?

A .gitignore file tells Git which files or folders to ignore in a project. It's usually placed in the root directory of a repository.

Common uses:

  • Ignore build output directories (e.g., dist/, build/)
  • Skip dependency directories (e.g., node_modules/, vendor/)
  • Exclude environment files with secrets (e.g., .env)
  • Ignore OS-specific files (e.g., .DS_Store on macOS)
  • Skip IDE and editor files (e.g., .vscode/, .idea/)

Basic rules:

  • file.txt - Ignores exact filename
  • *.txt - Ignores all .txt files
  • build/ - Ignores build directory and its contents
  • **/logs - Ignores logs directories in any location
  • !important.txt - Never ignore important.txt

Ready to create your .gitignore? Choose a template for your project:

Sponsored by


Templates