gitpractice.dev

brewly — Ch.4 · A secret in your last commit

Exercise 8 of 9

Before you start

Secrets do not belong in git

Passwords and keys must never be committed: anyone with the repository can read every old version.

You have not pushed yet, so you can still fix the commit itself.

git rm --cached <file> stops tracking a file but keeps it on your disk. Then list it in .gitignore (type it in the editor and save), stage that, and amend.

git rm --cached <file>
remove from git, keep the file
git add .gitignore
stage the new ignore rule
git commit --amend --no-edit
replace the last commit
git show --stat HEAD
which files are in the commit now?
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