Skip to content
Go back

Keeping secrets out of Git

Edit page

Keeping secrets out of Git

Secrets, credentials, and keys belong on the local disk and nowhere else — not in a commit, not in a push, not in a branch, not in a pull request. Once a secret reaches a remote it is exposed, even if a later commit deletes it, because git keeps history. This note lists what to consider and what to change in a repository so a secret cannot slip in.

Infographic: keeping secrets out of git — the committed-equals-compromised warning, the kinds of secrets, the .gitignore patterns, guard-not-a-wall, the README/AGENTS policy, three verify commands, and the safe habit

What to consider

What to edit in .gitignore

List the patterns secrets usually arrive in, so git cannot track them:

# Secrets, credentials, keys — never commit or push
.env
.env.*
*.key
*.pem
*.p12
*.pfx
id_rsa
id_ed25519
secrets/
credentials/

Add a pattern when a new tool introduces a new secret file.

What to add to README.md

State the policy where a reader sees it:

Secrets, credentials, and keys are never committed or pushed; they stay on the local disk, and .gitignore excludes their usual patterns.

If the README is generated — as in this repo, from articles.yaml — add the line to the template or the source that produces it, never by editing the README by hand.

What to add to AGENTS.md

Give the agent the same rule, so it does not stage or commit a secret:

Never commit or push secrets, credentials, or keys; they stay on the local disk. .gitignore excludes their usual patterns.

Verify

btw, i use arch


Edit page
Share this post on:

Next Post
Encrypting Linux: from a hack 20+ years ago to firewalls, LUKS and Veracrypt