📝 Git & GitHub

.gitignore Guide

P
Author
Pyland
📅
Published
06.05.2026
⏱️
Reading time
1 min
👁️
Views
143
🌿
Level
Medium

.gitignore is a file that tells Git which files NOT to track.

Why Do You Need It?

Without .gitignore you might accidentally commit:
- node_modules/ — 200 MB of dependencies
- .env — database passwords and API keys
- *.log — log files taking up tens of MB
- .DS_Store — macOS junk files

What NOT to Commit

# Dependencies (installed via pip/npm)
__pycache__/
*.pyc
.venv/
venv/
node_modules/

# Secrets and passwords — NEVER!
.env
.env.local
secrets.yml
*.pem
*.key

# Compiled code
dist/
build/
*.exe
*.pyc

# Logs and temp files
*.log
*.tmp

# OS system files
.DS_Store       # macOS
Thumbs.db       # Windows

# IDE configs
.vscode/
.idea/

# Local databases
*.sqlite
*.sqlite3
db.sqlite3

Syntax

secret.txt          # specific file
logs/               # directory
*.log               # all files with extension
**/temp.txt         # in any subdirectory
!important.log      # exception — do NOT ignore
# comment

Templates by Language

Python / Django

__pycache__/
*.py[cod]
.venv/
venv/
dist/
build/
*.egg-info/
.env
db.sqlite3
media/
staticfiles/

Node.js

node_modules/
dist/
build/
.next/
npm-debug.log*
.env

Java

*.class
*.jar
target/
build/
.gradle/

Ready-made templates: gitignore.io or select a template when creating a repository on GitHub.

Management

Global .gitignore (applies to all projects):

git config --global core.excludesfile ~/.gitignore_global

Check whether a file is ignored:

git check-ignore -v node_modules/
git status --ignored

If You Accidentally Committed a Secret

  1. Immediately rotate the compromised key/password
  2. Remove from history:
    bash git filter-branch --tree-filter 'rm -f .env' HEAD git push --force
  3. Note: old commits may still exist in forks

Common Mistakes

node_modules   # ❌ — ignores a file named "node_modules"
node_modules/  # ✅ — ignores the directory

 .env   # ❌ — leading space, won't work
.env    # ✅

Create .gitignore at the very start of the project — removing a file from Git history is much harder than never adding it.

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

Your First Git Commit

Git will create a hidden .git folder — everything is stored there.

📅 30.06.2026 👁️ 112
📝

Git Hosting Platforms

GitHub, GitLab, Bitbucket — key differences and recommendations.

📅 06.05.2026 👁️ 308
📝

What Is a Git Commit and Why Do You Need It? 📸

A commit is a saved snapshot of your project at a specific point in time...

📅 06.05.2026 👁️ 171

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!