๐Ÿ“ Git & GitHub

.gitignore Guide

P
Author
PyLand Team
๐Ÿ“…
Published
06.05.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
383
๐ŸŒฟ
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

๐Ÿ“

Undo and Revert in GitHub Desktop: Fix Mistakes Wโ€ฆ

A commit is not a point of no return. GitHub Desktop lets you rebuild a...

๐Ÿ“… 16.07.2026 ๐Ÿ‘๏ธ 359
๐Ÿ“

History, Diffs, and Web Commits on GitHub

GitHub lets you read repository history, inspect individual commit diffs, view the history of one...

๐Ÿ“… 16.07.2026 ๐Ÿ‘๏ธ 312
๐Ÿ“

Your First Git Commit

Your first commit starts with initializing a repository, configuring the author identity, and selecting the...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 343