Running git command line under Windows 7, I was finding that “git mv” to move a directory to a new location was not working. Some folders would move, and some would not, giving me this error instead:
$ cd foo
$ git mv my_folder new_parent_folder/
fatal: renaming 'foo/my_folder' failed: Permission denied
I noticed that the folders which would not move were folders where I had already changed a file and committed to git and even pushed back up to the repository server (github). It turned out that something had a lock on the folders that I was trying to move. Closing the git bash shell made no difference. Closing all editors and Explorer sessions made no difference.
The only thing that fixed this was to kill the Explorer process from the Windows process manager. Luckily in Windows 7 this is fairly easy, and it can be restarted without losing open applications and working files. But why is it necessary to do this, and is there something less severe that can be done to release those locks? No idea yet, but I’ll keep looking and am open to suggestions. I have a workaround in the meantime, even if it does involve giving Windows a kick in the teeth to get it to behave.
Just as an aside, whenever I am moving anything into a new folder, I always put the ‘/’ on the end of the destination folder. This avoids accidentally renaming the files if the destination folder is misspelled or happens not to be a folder after all. This has saved my bacon a number of times.