.gitignore Builder for Python

Generate a .gitignore for Python projects covering venv and artifacts

Creates a Python .gitignore covering __pycache__, .pyc files, virtual environments (venv and .venv), .env, dist and build artifacts, coverage, and common IDE folders, with toggleable sections.

Why ignore __pycache__?

__pycache__ holds compiled .pyc bytecode that Python regenerates automatically. It is machine-specific and pointless to commit, so it is always ignored.

A complete Python .gitignore

Python projects generate plenty of files you never want in version control: bytecode caches, virtual environments, packaging artifacts, and test coverage data. This builder produces a clean .gitignore for Python repositories, with each section toggleable so the file matches your exact toolchain.

How it works

Git applies each line of .gitignore as a pattern relative to the repository: a bare name matches anywhere below, a trailing slash matches directories, and globs like *.pyc match by extension. This builder assembles grouped sections — byte-compiled files (__pycache__/, *.pyc, *.pyo), virtual environments (venv/, .venv/, env/), environment files (.env), packaging (build/, dist/, *.egg-info/), testing (.pytest_cache/, .coverage, htmlcov/, .tox/), type checkers (.mypy_cache/, .ruff_cache/), and IDE folders (.vscode/, .idea/). Toggling a section includes or omits its block in the live output.

Tips and example

Keep your dependency manifest (requirements.txt, pyproject.toml, or poetry.lock) committed — it is not ignored here. A typical generated block includes:

# Byte-compiled files
__pycache__/
*.py[cod]
*.pyo

# Virtual environments
venv/
.venv/
env/

# Packaging
build/
dist/
*.egg-info/

# Testing
.pytest_cache/
.coverage
htmlcov/

If a cache folder was committed before you added this file, run git rm -r --cached __pycache__ to untrack it while keeping it locally.