Summary - .gitignore
- Git course
- Beginner
- Lesson 40/80
- 5 min
Combine patterns to write a project .gitignore file.
Create a project .gitignore
When creating a .gitignore file for a project, you can ignore temporary files, specific extensions, and generated directories using separate rules. Wildcards match multiple files, while directory patterns exclude specific directories. You can keep computer-specific personal rules in a global ignore file.
# .gitignore
*.log
*.tmp
build/
cache/Separating project rules from personal rules helps keep repository files organized.
Practice Write a project .gitignore file
Write these three rules on separate lines in .gitignore: ignore all .log files, all .tmp files, and the build/ directory. Do not add any other rules.
Starter code
# Günlük dosyaları
# Geçici dosyalar
# Derleme klasörüSample solution
# Günlük dosyaları
*.log
# Geçici dosyalar
*.tmp
# Derleme klasörü
build/Expected output
*.log *.tmp build/
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 You want to ignore .log files, .tmp files, and the build directory in a project. Which content combines the correct rules?
- *.log *.tmp build/ Correct answer
- log tmp build
- git log git status git add
- *.html *.css source/
Explanation: <code>*.log</code> and <code>*.tmp</code> ignore files with those extensions, while <code>build/</code> ignores the directory.
2 Complete the global file configuration key
git config --global ____
git config --global core.excludesfile
Explanation: <code>core.excludesfile</code> specifies the location of the global ignore file.
3 Combine ignore rules
| Term | Meaning |
|---|---|
*.log |
All files with the log extension |
*.tmp |
All temporary tmp files |
build/ |
Ignores the build directory |
core.excludesfile |
Sets the global file path |