In Git, by default, filenames are case-insensitive. This means that if you work on a case-insensitive filesystem (such as Windows or macOS's default filesystem), Git treats 'README.md' and 'readme.md' as identical files. However, on case-sensitive filesystems (such as Linux), these filenames are treated as distinct files.
How to Make Git Case-Sensitive?
If you need Git to be case-sensitive in a default case-insensitive environment, configure the core.ignorecase setting. To check the current setting, use the following command:
bashgit config core.ignorecase
If the command returns true, Git is currently case-insensitive. To make Git case-sensitive, set this option to false:
bashgit config core.ignorecase false
Example
Suppose you have a file named 'readme.md' in a project and you want to add a new file 'README.md' while ensuring Git treats them as distinct.
First, ensure Git is configured to be case-sensitive:
bashgit config core.ignorecase false
Then, add the new file and commit:
bashtouch README.md git add README.md git commit -m "Add README.md with different case"
In this way, Git treats 'README.md' and 'readme.md' as distinct files and tracks them separately in the commit history.
Notes
- In collaborative projects, standardize filename case sensitivity from the start to avoid confusion caused by inconsistent casing.
- If your project runs on multiple operating systems, explicitly mention filename case sensitivity in documentation and guides to ensure all team members configure Git correctly.
- After changing the
core.ignorecasesetting, recheck the existing file status to prevent accidental renaming or merging of files.