We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Patterns

It would be rough if .gitignore files only accepted exact filepath section names. Luckily, they don't!

Let's go over some of the most common patterns.

Wildcards

The * character matches any number of characters except for a slash (/). For example, to ignore all .txt files, you could use the following pattern:

*.txt

This would ignore files like /princess_diaries.txt and /contacts/your_mom.txt since they're both .txt files.

Rooted Patterns

Patterns starting with a / are anchored to the directory containing the .gitignore file. For example, this would ignore a main.py in the root directory, but not in any subdirectories:

/main.py

This ignores /main.py but not /src/main.py since /src is a subdirectory.

Negation

You can negate a pattern by prefixing it with an exclamation mark (!). For example, to ignore all .txt files except for important.txt, you could use the following pattern:

*.txt
!/important.txt

This would not ignore /important.txt, but would ignore /self_affirmations/important.txt.

Comments

You can add comments to your .gitignore file by starting a line with a #. For example:

# Ignore all .txt files
*.txt

Comments are especially helpful when doing something unconventional or complex, especially when collaborating.

Order Matters

The order of patterns in a .gitignore file determines their effect, and patterns can override each other. For example:

temp/*
!temp/instructions.md

Everything in the temp/ directory would be ignored except for instructions.md. If the order were reversed, instructions.md would be ignored.

You can read more about the patterns that are available in the official documentation.

Assignment

Use this .gitignore file (located at the project root) to answer the question:

# *.js

*.txt
!names.txt

/src/main.py

content.md