If you need to git delete file
but keep it locally (like when you want to stop tracking a file without losing it from your working directory), there’s a special way to do that too. You can use:
git rm --cached file1.txt
git commit -m "Stop tracking file1.txt"
This removes the file from the repository but keeps it on your local disk. I often use this when I accidentally commit configuration files or .env
files that shouldn’t be in version control. Just don’t forget to add the file to .gitignore
afterward to avoid accidentally tracking it again!