How to Properly Rename a Directory in a Git Repository
Sometimes, it is necessary to rename a directory in a git repository. Git allows doing it with the help of the git mv command. Below, we will describe how it works.
Renaming a Git directory in a Repository¶
You should run the git mv command like this:
git mv <old-name> <new-name>
Sometimes, carrying out a case-sensitive rename may require to take two steps:
git mv casesensitive tmp git mv tmp CaseSensitive
This system is not a very appropriate solution; nevertheless it works perfectly. Though the system doesn’t recognize the change of the letter case, Git does. That is why it is considered as a preferred way of renaming folders in Git world.
The git mv Command¶
The git mv command takes two arguments: a source and a destination. To move a number of files to a single path, you can specify “n” sources, but the last argument is the destination. First, it renames the source, which must exist and be either a file, symlink, or directory. The last argument must be an existing directory to which the given sources should be moved.