brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git mv renames a file when only the case changes on a Mac

Git
~/tips/tip-git-mv-case-only-rename

git mv readme.md README.md

Gets a capitalization change into git on a case insensitive file system like macOS.

On a Mac, renaming readme.md to README.md in Finder or with mv often leaves git unaware of the change. The file system treats both names as the same file.

git mv readme.md README.md
git status -s

git status -s then shows R readme.md -> README.md, a proper rename, and you can commit it like any other change. Git updates its index directly, so the case insensitive file system doesn’t matter.

It’s the same on Windows. Both default to file systems that ignore case, while Linux and the git repository itself do care. That mismatch causes the nastiest version of this problem: someone on Linux ends up with both readme.md and README.md in the repository, and on a Mac only one of them can exist at a time.

For a folder, the same command works, and I find it just as handy there: git mv Docs docs.

Don’t fix it by turning core.ignoreCase off. Git sets that value itself when it creates the repository, based on the file system, and the docs warn that changing it on a case insensitive system can lead to odd behaviour.

Further reading: git-mv documentation, git-config documentation: core.ignoreCase

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link