pastesite.com New paste

Share a Git diff without shipping a secret

By · Published 2026-11-23 · reviewed 2026-11-13 · 3 min read

AI-assisted article. Reviewed by Codebuff automated editorial review on 2026-11-13. Examples are illustrative, not real user data.

A diff is the most useful thing you can attach to a code question and the easiest way to leak a credential. It is a snapshot of the working tree, so it carries whatever was in the file at the moment you ran the command: a token you pasted to test something, a connection string you switched to locally, a customer identifier you hard-coded to reproduce a bug. The hunks themselves are usually fine. The values inside them are the problem, and the fix is to rewrite those values rather than to trim the diff until the question no longer makes sense.

What does a diff include besides your change?

The hunks are only part of the output. The header names both revisions, the file mode line says whether a file became executable, and a binary file is announced by name. If you added a file by accident, the diff names it even when you never opened it again.

That matters because the accidental additions are rarely the interesting ones. A stray `.env` or a local override sits in the diff beside the two-line fix you actually want reviewed, and the reviewer scrolls past it just as quickly as you did.

Find the values before you send the file

Read the added lines, not the whole diff. Anything that looks like a credential usually has a recognisable shape: a long random tail, a prefix such as `sk_live_` or `ghp_`, a connection string with a password before the `@`. Check the removed lines too, because a diff that replaces a real key with a placeholder still contains the key.

If the diff is large, a search over the added lines is faster than reading: filter for lines beginning with a plus and then grep those for the usual markers. Keep the result in the terminal rather than in a file you might attach by mistake.

# The diff, before it is rewritten
$ git diff HEAD -- src/config.ts
@@ -12,7 +12,7 @@ export const config = {
   region: "eu-west-1",
-  stripeKey: process.env.STRIPE_KEY,
+  stripeKey: "[REDACTED_STRIPE_SECRET]",
   retries: 3,
 };

# The same change, with the value replaced and the shape kept
$ git diff HEAD -- src/config.ts
@@ -12,7 +12,7 @@ export const config = {
   region: "eu-west-1",
-  stripeKey: process.env.STRIPE_KEY,
+  stripeKey: "[REDACTED_STRIPE_SECRET]",
   retries: 3,
 };

Rewrite the value, keep the hunk

Replacing a literal with its placeholder keeps the diff readable: the reviewer can still see that a string changed where an environment variable used to be, which is the actual question. Deleting the hunk removes the evidence and invites a guess about what you changed.

Use a placeholder that says what kind of value it was rather than a wall of asterisks. `[REDACTED_STRIPE_SECRET]` and `<database-password>` tell the reader what to look for; a uniform block of `XXXX` makes the two lines look identical. When the value is the bug, say so in the message instead of pasting it.

Send the command and the base revision

A diff without its base is ambiguous: the reviewer cannot tell whether a line is new or merely changed relative to a branch they have never fetched. Include the command you ran and the two revisions it compared, such as `git diff origin/main...HEAD -- src/config.ts`.

Use `--no-color` if you are pasting into a plain-text field, since escape sequences survive copy and paste and make the block unreadable. For a multi-commit branch, `git format-patch` or `git diff --stat` plus the full diff over the same range gives a reader enough to reconstruct the change.

Sources and editorial review

Prepared with AI assistance and checked against the code and password-protection sharing pages at the reviewed revision: the header-and-hunk explanation, the added-line search advice, placeholder choice, and the base-revision guidance. The example token is a clearly fake prefix followed by REDACTED and no real credential format is reproduced.