gitpractice.dev

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”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path