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"
More on Commits, branches and tags
How do you write a good commit message?BeginnerWhat is the difference between `git add .`, `git add -A` and `git add -u`?BeginnerHow do you commit only part of the changes in a file?BeginnerHow do you change the last commit message or add a forgotten file?BeginnerWhat is the difference between `git switch`, `git restore` and `git checkout`?BeginnerWhat is the difference between lightweight and annotated tags?Beginner