What is gitignore?

A .gitignore file is a plain text list that tells Git which files or folders it should completely ignore. Anything matching the patterns inside this file will not be tracked, shown as changes, or added to commits.

Let's break it down

  • File name: The file is literally called .gitignore and lives in the root of your repository (you can also have additional ones in sub‑folders).
  • Pattern syntax: Each line is a pattern (e.g., *.log for all log files, node_modules/ for a whole folder).
  • Comments: Lines starting with # are comments and are ignored by Git.
  • Negation: Prefix a pattern with ! to re‑include a file that was previously ignored (e.g., !important.txt).
  • Order matters: Git reads the file from top to bottom, so later rules can override earlier ones.

Why does it matter?

  • Keeps the repo clean: Prevents temporary, generated, or sensitive files (like passwords, compiled binaries, or IDE settings) from cluttering the history.
  • Reduces size: Large files that don’t need version control (e.g., node_modules) stay out, making clones and pushes faster.
  • Protects secrets: Accidentally committing API keys or config files can be a security risk; .gitignore helps avoid that.
  • Improves collaboration: Team members see only the files that truly matter to the project.

Where is it used?

  • In any Git‑based project: web apps, mobile apps, libraries, scripts, etc.
  • Commonly found in open‑source projects on GitHub, GitLab, Bitbucket, and in private company repositories.
  • Development tools often generate a starter .gitignore (e.g., git init, IDE templates, language frameworks).

Good things about it

  • Simple plain‑text format, easy to edit with any editor.
  • Works across all operating systems and Git clients.
  • Can be version‑controlled itself, so the ignore rules travel with the project.
  • Supports wildcards, directory rules, and negation for flexible control.
  • Multiple .gitignore files can be placed in sub‑directories for localized rules.

Not-so-good things

  • If a file was already committed before being added to .gitignore, Git will continue tracking it; you must remove it from history manually.
  • Complex patterns can become hard to read and maintain, especially in large projects.
  • Over‑ignoring may hide files that should be versioned, leading to missing assets or configuration drift.
  • .gitignore is repository‑specific; personal ignore preferences need a separate global ignore file (~/.gitignore_global).