brewly — Ch.4 · A secret already on the server
Exercise 9 of 9
Before you start
Pushed means leaked
Once a key is on a server, assume somebody has it. The first step is not git: replace the key so the old one stops working. Here the "Write the code" button does that and puts the new key in your file.
Then stop tracking the file and ignore it. The old commit still contains the old key, which is harmless once it is revoked.
Tools exist that rewrite all history to erase a secret. They change every commit after it and need the whole team, so they are a last resort and never replace revoking the key.
- git rm --cached <file>
- remove from git, keep the file
- git add .gitignore
- stage the ignore rule
- git commit -m "What you did"
- commit both changes
- git push
- share the fix
You can reopen this any time with “Lesson”.
.gitignoreEdit the file, then save.
Graph
- 6e8d9e3 Prepare card paymentsHEAD → mainorigin/main
- 1354d06 Add menu page
- 619eb3b Style the order button
- 5fc44ac Initial commit