Move all files of a git directory into subdirectory and maintain history

The solution to make the git mv work is simple:

git mv -k * ./subDir

The option -k will simply skip all actions that would produce an error. This will probably not work in older versions of git.

Remember there is the mv and the git move.

The normal bash move usage is: mv * ./subDir which will only produce a warning but still move your files.

Whereas the git mv with the usage git mv * ./subDir will produce the fatal error and abort the move:

fatal: can not move directory into itself, source=currentDir/subDir, destination=currentDir/subDir/subDir

Leave a Comment