← Git from Scratch Lesson 7 of 17 · 10 XP

.gitignore: what not to store

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

Not everything in a project folder should go into git:

  • secrets: .env, keys, passwords;
  • things that are generated automatically: __pycache__/, node_modules/, *.o, the build folder;
  • logs and temporary files: *.log, *.tmp;
  • personal editor settings: .vscode/, .idea/.

The list of exclusions goes into a .gitignore file in the project root, one pattern per line:

*.log
.env
__pycache__/
build/

The .gitignore itself is committed: the whole team needs the rules.

Important: .gitignore only affects files that are not tracked yet. If a secret has already got into a commit, adding it to .gitignore isn't enough: it stays in the history. You need to remove it from the repository (git rm --cached file) and change the secret itself, because the history may already have leaked.

In your IGD project, .gitignore contains .venv/, db.sqlite3 and static/vendor/. That's exactly why the huge C compiler didn't end up in the repository.

Task. The folder contains app.py, debug.log and secret.env. Create a .gitignore that excludes all .log files and secret.env, then run git add . and commit with the message init project. Only .gitignore and app.py should go into the commit.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.