Git — .gitignore
.gitignore Patterns
# Comment
*.log # All .log files
!important.log # Except this one
/build/ # Build directory
dist/ # Dist directory
.env # Environment file
Language-Specific
JavaScript
node_modules/
package-lock.json
yarn.lock
Python
__pycache__/
*.pyc
.env
venv/
Java
*.class
*.jar
target/
Global .gitignore
git config --global core.excludesfile ~/.gitignore_global
# ~/.gitignore_global
.DS_Store
*.swp
.vscode/
.idea/
Commands
# Check if file is ignored
git check-ignore file.txt
# Remove from tracking
git rm --cached file.txt
# Stop tracking but keep local
git rm -r --cached folder/
Mini Practice
- Create .gitignore
- Add patterns
- Use global ignore
- Stop tracking files
Up Next
Continue with Conflicts — resolving merge conflicts.
Related Topics
Frequently Asked Questions about .gitignore
What is .gitignore in Git?
.gitignore is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn .gitignore?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn .gitignore.
Why is .gitignore important in Git?
.gitignore is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.