What Never Goes Into Git
Secrets, local settings, generated files and personal backups do not belong in a repository. How .gitignore, .dockerignore and habits keep them out.
Git remembers forever
A file committed once stays in history even after it is deleted. Anyone with a copy of the repository can find it. That is wonderful for code and terrible for a password. So the question "should this be in Git?" has to be asked before the commit, not after.
The four kinds of thing that stay out
| Kind | Examples | Why |
|---|---|---|
| Secrets | API keys, passwords, the .env file |
Anyone with the repository could use them |
| Installed or generated files | node_modules/, build output, reports |
Rebuilt from the lock file or the scripts; large and noisy |
| Machine-local files | Editor settings, OS files, local backups | Mean nothing on another machine |
| Personal working files | Scratch scripts, downloads, drafts | Clutter that confuses the next reader |
.gitignore
A .gitignore file lists patterns Git should never pick up. On this site it covers, among others, .env and .env.*, node_modules/, timestamped backup files and a scripts/_local/ folder for throwaway scripts. Two lessons:
- Ignore the pattern, not the instance.
.env.*catches.env.localand.env.productiontoo. - Ignoring a file does not untrack it. If a file was committed before the rule was added, remove it from the index with
git rm --cached <file>and commit that.
.dockerignore
The Docker build has its own ignore file, and it matters just as much. Everything not ignored is copied into the image. On this site .dockerignore keeps out .git, .env, node_modules (installed fresh inside the image), backups, archives and Markdown documentation files that the server does not read. A secret that is safe from Git can still leak into an image if this file forgets it.
Stage files by name
The habit that prevents most accidents:
git status
git add content/corporate/devops/index.md lib/about/devops.js
Never git add -A or git add . in a busy folder. You see exactly what goes in, and a stray file stays out.
"Git is the backup"
This site's layout rule says: do not create backups/ folders or dated copies of files. Git already keeps every version of every committed file. A folder of page.md.backup-2026-11-21 copies only adds noise, gets picked up by searches and tests, and is never the version you want anyway. If you need an old version:
git log --oneline -- path/to/file
git show <commit>:path/to/file
If a secret is committed
Assume it is compromised the moment it is pushed. In order:
- Rotate it: create a new key at the provider and revoke the old one. This is the step that actually protects you.
- Update the new value wherever it is used (see Moving Secrets into Secret Manager).
- Remove the file and add the ignore rule.
- Only then think about rewriting history. Rewriting helps, but copies may already exist; rotation is what makes the old value useless.
Try it yourself
Run git ls-files | grep -iE "env|secret|key|backup|\.bak" in your repository. Every result deserves a second look. Then compare your .gitignore and .dockerignore side by side: a secret should be listed in both.