.gitignore Files


Programming projects are required to include a .gitignore file in the root directory of the repository unless an assignment specifically states otherwise. The purpose of the file is simple: keep files that belong to the project under version control, and keep generated, local, temporary, or private files out of the repository.

A clean repository should contain the files needed to understand, build, test, and maintain the project—not files created by your operating system, editor, IDE, compiler, runtime, or local development environment.

Keep your .gitignore minimal, project-specific, and understandable. Do not copy a large generic template containing entries you do not understand.


What Belongs in .gitignore

Ignore files and directories that are created locally and do not belong in the shared project history. Common examples include:

  • compiler and build output;
  • language caches and generated files;
  • temporary files;
  • IDE- or editor-specific files;
  • operating-system metadata;
  • local virtual environments; and
  • local configuration files or files containing secrets.

What Does Not Belong in .gitignore

Do not ignore files that are part of the actual project or are required by the course. These normally include:

  • source code;
  • tests;
  • required documentation such as README.md;
  • assignment files and required project configuration; and
  • Classroom 50 system files such as .github/ and .classroom50.yaml.

If you cannot explain why an entry is in your .gitignore, it probably should not be there.

Style

  • Place .gitignore in the root directory of the repository.
  • Include only entries that are relevant to the project.
  • Use comments beginning with # to organize or explain groups of entries when the file contains more than a few patterns.
  • Keep the file readable. Group related patterns together.
  • Do not use .gitignore as a substitute for understanding what belongs in the repository.

Example

The following is an example only. Your project may need fewer entries, different entries, or additional entries depending on the language and tools being used.

# Build output
build/
*.o

# Python cache
__pycache__/
*.pyc

# Local environment
.env
.venv/

# Editor / OS files
.idea/
.DS_Store

Important Rules

  • .gitignore applies to files Git is not already tracking. Adding an already committed file to .gitignore does not remove it from repository history.
  • .gitignore is not a security system. It can help prevent accidental commits of local secret files, but a password, API key, or other secret that has already been committed must be treated as exposed.
  • A clean repository is not one that ignores as much as possible. It is one that tracks everything the project needs and excludes everything it does not.

Reference

For additional details on .gitignore syntax and patterns, see: Atlassian Git Tutorial: .gitignore .