Will not add file alias 'samefile' 'SameFile' already exists in index when git add operation
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The error "will not add file alias 'samefile' ('SameFile' already exists in index)" occurs when you try to git add a file on a case-insensitive file system (macOS, Windows) and a file with different casing already exists in the Git index. For example, if SameFile.txt is tracked and you create samefile.txt, the OS treats them as the same file but Git's index considers them different. Fix it by removing the old entry with git rm --cached OldName, then adding the correctly-named file.
Why It Happens
Git's index is case-sensitive, but macOS (APFS default) and Windows (NTFS) file systems are case-insensitive:
Fix 1: Rename Using git mv
If git mv fails because the OS sees them as the same file, use a two-step rename:
Fix 2: Remove from Index and Re-Add
Fix 3: Fix a File Created by Another OS
If a collaborator on Linux created both file.txt and File.txt (different files on Linux, same file on macOS/Windows):
Diagnosing the Problem
Preventing the Issue
git config core.ignorecase
Do NOT set core.ignorecase=false on a case-insensitive file system — it causes Git to track phantom changes and produce confusing behavior.
Pre-Commit Hook to Detect Case Conflicts
Handling Directory Case Changes
Cross-Platform Team Workflow
If your team uses both Linux and macOS/Windows:
Common Pitfalls
- Setting
core.ignorecase=falseon a case-insensitive file system: This causes Git to see phantom changes — it thinks a file was deleted and a new one created whenever casing differs between the index and the working tree. Only set this tofalseon truly case-sensitive file systems (Linux ext4, APFS with case sensitivity enabled). - Using
git add .after renaming a file's case on macOS: The OS reports no change (same file), sogit add .does not update the index. Usegit mvor the two-stepgit rm --cached+git addapproach. - Collaborators on Linux creating files that differ only by case: Linux allows
file.txtandFile.txtas separate files. When a macOS or Windows user clones the repo, only one file appears and the other causes errors. Establish a naming convention to avoid case-only differences. - Forgetting
--cachedwhen removing the old entry:git rm SameFile.txt(without--cached) deletes the file from both the index and the working tree. Usegit rm --cached SameFile.txtto remove only the index entry while keeping the file on disk. - Renaming a file in a file manager and expecting Git to detect it: File managers on macOS/Windows may not create a new file when changing case — they just update the directory entry. Git does not see this as a change. Always use
git mvfor case changes.
Summary
- This error occurs because Git's index is case-sensitive but macOS/Windows file systems are not
- Use
git mv OldName newname(or two-step rename through a temp name) to change file casing - Use
git rm --cached OldName+git add newnameas an alternative fix - Use
git ls-files | sort -f | uniq -Dito find case conflicts in the repository - Never set
core.ignorecase=falseon a case-insensitive file system

