Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a Git repository, how to properly rename a directory?

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?

like image 654
qazwsx Avatar asked Jun 25 '12 05:06

qazwsx


People also ask

How do you rename a directory in git?

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.

How do you rename a directory?

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.

How do I rename a directory in git without losing history?

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.


2 Answers

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.

like image 84
CB Bailey Avatar answered Oct 11 '22 07:10

CB Bailey


If you receive this error: fatal: renaming ‘foldername’ failed: Invalid argument

Try this:

*nixOS

git mv foldername tempname && git mv tempname folderName

WinOS

git config core.ignorecase false; git mv foldername tempname; git mv tempname folderName

like image 28
Jacques Betancourt Avatar answered Oct 11 '22 06:10

Jacques Betancourt