Alejandro Napoles

Alejandro Napoles

Thoughts and ideas about programming, technology and my life as a lifelong learner and developer.




Rename directories in Git

Alejandro NapolesAlejandro Napoles

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