Lesson 42 +15 XP

Git .gitignore

Git .gitignore

A .gitignore file tells Git which files and folders to ignore, so they never get committed.

Create the file

In your repository root, create a file named exactly:

.gitignore

What to ignore

  • Secrets like .env or config.php
  • Build folders like node_modules, dist, build
  • Log files like *.log
  • OS files like .DS_Store or Thumbs.db
  • Compiled files like .class or .exe

Example .gitignore

node_modules/
dist/
.env
*.log
.DS_Store

The star pattern

matches any file name. So .log ignores every file ending in .log, and *.txt ignores every .txt file.

Folder and rule endings

  • A trailing slash like node_modules/ ignores a whole folder.
  • Lines starting with # are comments.

Check what would be ignored

git status

Ignored files simply do not show up. To check a rule:

git check-ignore -v myfile.log

TL;DR

  • .gitignore lists files Git should never track.
  • Use it for secrets, build folders, and logs.
  • * matches any file name.
  • Ignored files disappear from git status.