Q: You added `config.yaml` to `.gitignore` but Git is still tracking it and showing it as modified. Why, and how do you fix it?
.gitignore only prevents new files from being tracked. It does not untrack files that are already in the repo. Git is still watching conf...
#Git #Undo, Recovery & History Rewriting #L1 #Version Control #Collaboration
🎙️ Candidate Opening & Architectural Context
""When an engineer accidentally creates this branch or commit divergence, I walk them through safe recovery without data loss. The interviewer is testing: Understanding that `.gitignore` only affects untracked files.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Production Solution & Architecture
.gitignore only prevents *new* files from being tracked. It does not untrack files that are already in the repo. Git is still watching config.yaml because it was committed before the ignore rule existed. Fix it by removing the file from the index while keeping it on disk: The --cached flag is critical — without it, git rm deletes the local file too. After the commit, .gitignore will keep it out going forward. For a whole directory: git rm -r --cached path/to/dir. To re-check what Git is currently tracking that *should* be ignored: git ls-files -ci --exclude-standard.
git rm --cached config.yaml
git commit -m "Stop tracking config.yaml"
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: .gitignore only prevents *new* files from being tracked. It does not untrack files that are already in the repo. Git is still watc."
⚡ 60-Second Elevator Pitch Talking Points
- Immediate Triage: .gitignore only prevents new files from being tracked. It does not untrack files that are alrea
- Run targeted verification commands before modifying configuration.
- Automate permanent guardrails (CI check, alerts, IaC policy) to prevent recurrence.
Advertisement