---
title: "Gitignore Patterns Cheatsheet | FindUtils"
description: "Check .gitignore patterns, directory scope, exceptions, and tracked-file limits. Diagnose matching rules with Git check-ignore examples."
url: https://findutils.com/cheatsheets/gitignore-patterns/
---

# Gitignore Patterns Cheatsheet

Check .gitignore patterns, directory scope, exceptions, and tracked-file limits. Diagnose matching rules with Git check-ignore examples. 40 commands in 7 sections, filed under [Git & Version Control](https://findutils.com/cheatsheets/git/).

## Scope and limits

- `Untracked files only`: Ignore rules do not remove files already tracked by Git
- `Ignore is not access control`: An ignore rule does not protect or encrypt a file
- `Last matching rule`: Within one rule level, the last matching pattern decides
- `Pattern examples are separate`: Combine only the examples that match your intended policy

## Files and extensions

- `*.log`: Match log names at any depth below this ignore file
- `debug.log`: Match this file or directory name at any depth
- `/debug.log`: Match this name only beside the ignore file
- `*.tmp`: Match names with a temporary-file extension
- `report?.csv`: Match report plus one non-slash character, then .csv
- `report[0-9].csv`: Match report plus one digit, then .csv

## Directories and paths

- `cache/`: Ignore directories named cache at any depth below this file
- `/cache/`: Ignore only the cache directory beside this ignore file
- `build/output.txt`: Match this path relative to the ignore file
- `docs/*.html`: Match direct HTML children of docs
- `docs/**/*.html`: Match HTML files inside docs at any depth
- `**/temp/`: Ignore directories named temp at any depth

## Exceptions and literal characters

- `*.log
!important.log`: Keep important.log eligible when no parent is excluded
- `/build/*
!/build/keep.txt`: Ignore build children except keep.txt
- `/cache/
!/cache/keep.txt`: This exception fails because its parent remains excluded
- `# Comment`: Add a comment on its own line
- `\#notes.txt`: Match a name that starts with a literal hash
- `\!important.txt`: Match a name that starts with a literal exclamation mark

## Inspect the rules

- `git check-ignore -v -- <file>`: Show a matching rule; ! marks an inclusion exception
- `git check-ignore --no-index -v -- <file>`: Check rule matching even when the file is tracked
- `git check-ignore -q -- <file>`: Return 0 for ignored, 1 for not ignored, or 128 on error
- `git status --short --ignored`: Show ignored paths with !! markers
- `git ls-files -- <file>`: Check whether this path is already tracked
- `git ls-files --others --ignored --exclude-standard`: List ignored untracked files using standard rule sources

## Choose where rules belong

- `.gitignore`: Commit shared rules that apply to the project
- `.git/info/exclude`: Keep rules for this local repository only
- `core.excludesFile`: Configure a separate ignore file for personal patterns
- `Nested .gitignore`: Apply a rule to its directory and descendants
- `Already tracked file`: Plan an index change separately; ignoring alone has no effect
- `Exposed private data`: Ignoring later does not remove data from earlier commits

## Sources and related references

- `https://git-scm.com/docs/gitignore`: Check pattern syntax, precedence, and exceptions
- `https://git-scm.com/docs/git-check-ignore`: Check diagnostics and exit codes
- `https://git-scm.com/docs/git-ls-files`: Check index and ignored-file listings
- `https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files`: Choose shared and local ignore locations
- `/cheatsheets/git-history/`: Inspect recorded file history
- `/cheatsheets/git-branches-remotes/`: Review branches and remote state

## Related

- Cheatsheet: [Git History and Diffs](https://findutils.com/cheatsheets/git-history/)
- Cheatsheet: [Git Branches and Remotes](https://findutils.com/cheatsheets/git-branches-remotes/)
- Cheatsheet: [Git Commands](https://findutils.com/cheatsheets/git-commands/)
