CodeBlanks Logo Icon CodeBlanks

What is .gitignore?

Learn what the .gitignore file does.

What is .gitignore?

.gitignore is a special text file used to specify files and directories that you do not want Git to track. Files matching its patterns are not automatically added to the staging area if they are not already tracked. It is especially useful for temporary files, logs, and personal settings.

# .gitignore
*.log
cache/

This file prevents matching untracked files from appearing in the repository status.

Ignoring untracked files

.gitignore rules mainly apply to files that are not already tracked by Git. For example, if debug.log matches a pattern, Git will not show it in the untracked files list. However, a file committed earlier is not removed from tracking simply by adding it to .gitignore.

# .gitignore
debug.log

# Matching file
debug.log

For this reason, .gitignore is used to identify files that should not be added to the project in the first place.

Practice Keep a file out of Git

Add a rule to the .gitignore file that ignores secret.txt. The file should contain only this rule.

Starter code

terminal
# .gitignore
# Dışlanacak dosyanın adını yaz

Sample solution

terminal
# .gitignore
secret.txt

Expected output

secret.txt

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 You do not want Git to track log files in your project. Which pattern should be written in .gitignore?

  • *.html
  • git log
  • git add
  • *.log Correct answer

Explanation: The <code>*.log</code> pattern matches files with the .log extension.

2 Ignore a log file

Question
# .gitignore
____
Answer
# .gitignore
debug.log

Explanation: The <code>debug.log</code> line ignores an untracked log file with that exact name.

3 .gitignore use cases

Term Meaning
Geçici dosya A file not meant to be permanent
Günlük dosyası Application activity record
.gitignore Stores ignore rules
Untracked A file not yet tracked

All lessons in Beginner