Ignored Too Late
Git rm --cached.
Here's a common trap. You committed a file, and then added it to dot git ignore. But Git keeps tracking it anyway. Ignore rules only apply to files Git isn't already tracking.

- A file was committed
- Then added to .gitignore
- Git still tracks it
Stop tracking, keep the file
Our debug log was committed by mistake. We add it to dot git ignore, but the change still shows up in status. The fix is git r m, dash dash cached. Cached means remove it from Git only, and keep it on disk. Commit, and from now on, Git ignores it. And l s shows the file is still here.
echo '*.log' >> .gitignore git status --short M .gitignore M debug.log git rm --cached debug.log rm 'debug.log' git commit -am "Stop tracking debug.log" [main 0ede7f3] Stop tracking debug.log 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 debug.log git status --short ls about.html debug.log index.html style.css
Leaked a secret?
One important warning. If you ever commit a password or secret key, removing it now doesn't remove it from history. Anyone with the repository can still find it in old commits. Treat it as leaked. Change the password or key straight away. We'll come back to this later.
Summary
git r m dash dash cached stops tracking a file but keeps it on disk. And a committed secret must be changed. Next, cleaning junk out of your folder.
Key takeaways- git rm --cached <file>
- Then commit
- Leaked secrets: rotate them