Skip to main content

.gitignore Reference

Browse .gitignore syntax patterns and copy pre-built templates for popular languages and tools.

filename.txtbasic

Ignore a specific file in any directory

e.g. secret.txt, .env

/filename.txtbasic

Ignore only in the root directory (leading slash)

e.g. /TODO

# commentbasic

Comment line — ignored by Git

e.g. # Build artifacts

(blank line)basic

Blank lines are ignored

*.logwildcard

Ignore all files with .log extension

e.g. *.tmp, *.bak

*.{js,ts}wildcard

Ignore multiple extensions (brace expansion — not standard, use two lines)

e.g. *.js *.ts (safer)

**/*.logwildcard

Ignore .log files in all subdirectories

e.g. **/dist/**

file?wildcard

? matches exactly one character

e.g. file? matches file1, fileA

file[0-9]wildcard

[ ] matches a character range

e.g. file[abc] matches filea, fileb

build/*wildcard

Ignore all files inside build/ but not build/ itself

e.g. dist/*

!important.lognegation

Un-ignore a previously ignored file (negation)

e.g. !.env.example

!vendor/important/negation

Re-include a directory excluded by a parent rule

e.g. !src/lib/keep/

node_modules/directory

Ignore the directory and its contents (trailing slash = directory only)

e.g. .next/, dist/

logs/directory

Ignore any directory named 'logs' anywhere in the tree

e.g. tmp/, cache/

build/directory

Ignore build output directories

e.g. out/, .output/

doc/**/*.txtadvanced

Ignore all .txt files in doc/ and all its subdirectories

e.g. src/**/*.test.js

*/tempadvanced

Ignore any 'temp' file or dir exactly one level deep

e.g. */debug

\#file.txtadvanced

Escape # to treat it as a literal character

e.g. \!literal.txt