Menu
Coddy logo textTech

Gitignore Patterns

Part of the Version Control section of Coddy's Terminal journey — lesson 20 of 58.

The patterns inside .gitignore follow a few simple rules:

  • secret.txt: ignore an exact filename anywhere in the repo
  • *.log: ignore every file ending in .log
  • build/: ignore the entire build directory and everything inside it
  • logs/*.tmp: ignore .tmp files inside logs/ only
  • #: starts a comment line; ignored by Git
  • !important.log: an exception. Even if a previous rule matched it, this file is not ignored

Order matters when you mix rules and exceptions. Later patterns override earlier ones for files they both match.

One important warning: .gitignore only affects files that are not yet tracked. If a file was already committed, adding it to .gitignore will not stop Git from tracking it. You would need to remove it from the index first.

challenge icon

Challenge

Easy

The folder contains: main.py, secret.txt, tmp/cache.dat, and tmp/keep.md. Initialize the repo, create a .gitignore with these two lines:

secret.txt
tmp/

Then run git status --short. Only .gitignore and main.py should show up as untracked.

Cheat sheet

.gitignore pattern rules:

  • secret.txt — ignore exact filename anywhere in the repo
  • *.log — ignore all files ending in .log
  • build/ — ignore entire directory and its contents
  • logs/*.tmp — ignore .tmp files inside logs/ only
  • #comment — comment line, ignored by Git
  • !important.log — exception: do not ignore this file

Later patterns override earlier ones. .gitignore only affects untracked files; already-committed files must be removed from the index first.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control