Beginner LevelGit & GitHub
How do you stop tracking a file in Git without deleting it from local disk?
❓ Interview Prompt: Explain git rm --cached, removing files from Staging Area Index while preserving physical files on disk.
git rm --cached <file> removes the file from Git's Staging Area Index (un-tracking it), but leaves the physical file on your disk untouched! Add the pattern to .gitignore immediately after to prevent re-staging.
Code Implementation Example
bash
git rm --cached .env
echo ".env" >> .gitignore
git commit -m "fix: remove .env from Git tracking"💡Untracking files from Git index while preserving local physical files.
🎯 Interview Key Takeaway
Use git rm --cached <file> to remove files from Git tracking while preserving physical files on local disk.
#git rm --cached#Untrack Files#Beginner
Back to all Git & GitHub Questions→