QA
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→

More Git & GitHub Interview Questions

Beginner LevelGit & GitHub

Compare git rebase versus git merge and explain how git bisect finds regressions.

Beginner LevelGit & GitHub

What is the difference between git init and git clone?

Beginner LevelGit & GitHub

What are the Three Trees in Git (Working Directory, Staging Area / Index, Commit History)?