Course contentsShow
← Data Science
Lesson 1996 of 2,14546. Version Control with GitFree lesson

The .gitignore File

Excluding files from version control, creating .gitignore patterns, and handling data files and sensitive information.

The .gitignore File

You'll learn how to tell Git which files to intentionally ignore, protecting sensitive data and keeping your repository clean.

Why Ignore Files?

Not everything in your project folder belongs in version control. Raw datasets can be massive (hundreds of GB), API keys are sensitive, and temporary files like .DS_Store or __pycache__/ are just noise. Git lets you exclude these by listing them in a special file called .gitignore.

Think of .gitignore as a bouncer at an exclusive club: you give it a list of who's not allowed in, and Git obeys those rules automatically.

Creating a .gitignore File

In your repository's root directory, create a plain text file named .gitignore (note the leading dot). Each line specifies a pattern for files or folders to ignore:

# Ignore all CSV files
*.csv

# Ignore the entire data directory
data/

# Ignore environment files
.env
secrets.json

# Ignore Python cache
__pycache__/
*.pyc

# Ignore Jupyter checkpoints
.ipynb_checkpoints/

The # symbol denotes comments for readability.

Pattern Basics

  • *.csv — ignores all files ending in .csv
  • data/ — ignores the entire data folder (trailing slash means directory)
  • .env — ignores a specific file named .env
  • !important.csv — the ! prefix "un-ignores" a file (exception to a previous rule)

Data Science Best Practices

Always ignore:

  • Large data files — store these separately (cloud storage, data lakes)
  • Credentials — .env, config.json, API keys
  • Generated outputs — model binaries (.pkl), result CSVs you can regenerate
  • Environment artifacts — virtual environments, cache folders

Key Takeaway: The .gitignore file protects your repository from bloat and security risks by excluding data files, secrets, and temporary artifacts—essential for professional Data Science workflows.