Fix .gitignore Not Working and Git Filename Case Changes

Why .gitignore stops working and Git misses filename case changes, with three fixes: clear the cache, enable case tracking, and rename files with Git.

CChia1104
  • Notes
  • 1 minutes read

When working on development, I often encountered two common Git issues:

  • After updating .gitignore, already tracked files couldn’t be ignored.
  • When renaming files with different letter cases, Git didn’t detect the change.

.gitignore not taking effect

The reason is that Git caches files that are already tracked. If certain files have been committed before, adding them to .gitignore won’t make any difference. To fix this, you can remove the local cache and commit again.

git rm -r --cached .
git add .
git commit -m "fix: update .gitignore"

Here, the command git rm -r --cached . clears all cached files, but you can also specify individual file paths if needed.

Tracking case-sensitive file name changes in Git

By default, Git doesn’t track filename changes that only differ in letter case.

  1. One simple fix is to clear the cache and commit again.
git rm -r --cached .
git add .
git commit -m "fix: update file name"
  1. Another approach is to configure Git to track case-sensitive changes.
git config --local core.ignorecase false
  1. Finally, you can directly rename the file through Git itself.
git mv -f readme.md README.md
Last updated

Written by: Chia1104 CC BY-NC-SA 4.0