Interview Prep/Git & GitHub/Commits, branches and tags

What is `.gitignore` and why doesn't it ignore files that are already tracked?

BeginnerConceptCommits, branches and tags
Answer

.gitignore only affects untracked files. If a file is already in the index, Git keeps tracking it. Remove it from the index while keeping the local copy, then commit.

git rm --cached .env
echo ".env" >> .gitignore
git commit -m "chore: stop tracking .env"
All Git & GitHub questions Roadmap: Git & GitHub

More on Commits, branches and tags