Problem: Git wants to track ALL your files, even the useless ones:
.tmp)node_modules/).env).DS_Store)Solution: .gitignore
mkdir demo-gitignore && cd demo-gitignore
git init
# Create test files
echo "print('app')" > app.py
echo "SECRET_KEY=123456" > .env
mkdir temp && echo "cache" > temp/cache.tmp
mkdir logs && echo "error logs" > logs/app.log
# Without .gitignore, Git wants to track everything
git status # See all the files
# Create .gitignore
cat > .gitignore << EOF
# Sensitive files
.env
*.secret
# Temporary folders
temp/
logs/
build/
# System files
.DS_Store
*.tmp
EOF
# Now Git ignores these files
git status # Cleaner!Useful patterns:
| Pattern | Ignores |
|---|---|
*.log | All .log files |
temp/ | The entire temp folder |
.env* | All files starting with .env |
!important.log | Exception: keep this file |
build/** | Everything in build recursively |
Ready-to-use templates:
__pycache__/, *.pyc, .envnode_modules/, npm-debug.log*.class, target/# Check whether a file is ignored
git check-ignore -v .env # If ignored: displays the rule
git check-ignore logs/app.log # If ignored: nothing displayed
# Force-add an ignored file (if really needed)
git add -f fichier-ignore.tmp
# See all non-ignored files
git ls-filesGolden rule: Create your .gitignore at the START of the project!