Alejandro Napoles

Rename directories in Git

April 27th, 2016

I was trying to remove the capitalization of some directories in my project, but it didn’t turn out initially as I wanted. Although the paths inside the JavaScript files were changed and the directories too, Git didn’t care. If someone were to clone the project she would find the directories capitalized. This happens because Git by default is not case sensitive in my system (it depends on the core.ignorecase value, which you can see with git config core.ignorecase).

One way of making Git recognize the change is moving the contents of the directory to another, remove it or just change the capitalization, commit the change, create again the original one with the new name if you deleted it, move back the files to it and amend the previous commit, as in the following example:

> mkdir temp
> mv Original/* temp
> rm -d Original
> git add .
> git commit -am "Renamed directories"
> mkdir original
> mv temp/* original
> git add .
> git commit --amend --no-edit

A simpler way of doing it is using git mv:

git mv -f Original/* original  

It can also be done by changing the ignorecase value for the project:

git config core.ignorecase false

Alejandro Napoles

Written by Alejandro Napoles. Web developer. Twitter Github

Creative Commons Licence
alejandro napoles dot com byAlejandro Napoles is licensed under aCreative Commons Attribution - ShareAlike 4.0 International License