I think it should work to copy the directory to be renamed to a new directory with desired name, and delete the old directory, and git add
, git commit
and push
everything. But is this the best way?
To rename any file or folder, use git mv command which takes two arguments. The first argument is the source and the second is the destination. We can easily rename any file using the git command and the new name will be assigned to that file.
You rename a directory by moving it to a different name. Use the mv command to rename directories. You can also use mv to move a directory to a location within another directory. In this example, the directory carrots is moved from veggies to veggies2 with the mv command.
emiller/git-mv-with-history. git utility to move/rename file or folder and retain history with it. # git-mv-with-history -- move/rename file or folder, with history. # Git has a rename command git mv, but that is just for convenience.
Basic rename (or move):
git mv <old name> <new name>
Case sensitive rename—eg. from casesensitive
to CaseSensitive
—you must use a two step:
git mv casesensitive tmp git mv tmp CaseSensitive
(More about case sensitivity in Git…)
…followed by commit and push would be the simplest way to rename a directory in a git repo.
If you receive this error: fatal: renaming ‘foldername’ failed: Invalid argument
Try this:
git mv foldername tempname && git mv tempname folderName
git config core.ignorecase false; git mv foldername tempname; git mv tempname folderName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With