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.
Thanks! This saved me time and aggravation…
Also, if you’re just changing case for a directory, you will need to change it to an intermediate directory. i.e.
git mv app App-tmp
git mv App-tmp App
Thanks Reuben!. This helps!
Thanks Reuben, helped me out too!
That has been a Windows NT think since forever too. You had to use an intermediate file name when renaming the letter case of file names in Explorer. Windows 7 fixed that though, but I suspect some part of it is still lurking.
Thanks for the help !
It still amazed me how long some tips stay relevant!
Still relevant 🙂
thank you very much!
Fyi…this is what is meant by restart explorer:
http://www.wikihow.com/Restart-Windows-Explorer-Without-Rebooting-Computer
Seems it is a known bug in TortoiseGit:
https://code.google.com/p/tortoisegit/issues/detail?id=442
Note the hint at the bottom of the bug report:
“Killing the cache process allows the move.”
Hi, I dont know if you found a way to solve that issue yet. I got the same problem and you helped me to figure out how to fix it. I use a little utilitary named “Unlocker”, you can find it easily. It adds an entry in the explorer’s context menu to find which process are locking the file/folder.
Hope it can help.
Unlocker is awsome!
try using this
https://technet.microsoft.com/en-us/sysinternals/bb896653
I my case, it was Visual Studio code having the locks. I was able to move the folders after closing VS.
Thanks, this tip was very helpful! (and the fact that you documented it 7 years ago!) I would never have thought of killing explorer.
It is amazing how time flies and new things come along, and yet the trail of legacy code and tools remains and grows 🙂 Glad you found it useful. Can’t say I have *ever* had to deal with this again, since I posted it.
On my windows machine, I had closed eclipse but not git bash. It seems like eclipse leaves some java.exe processes running and after killing those with task manager, git mv worked