git mv “permission denied”

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.

18 Responses to git mv “permission denied”

  1. George 2013-11-15 at 09:33 #

    Thanks! This saved me time and aggravation…

  2. Reuben Helms 2014-01-27 at 23:59 #

    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

    • maquanjun 2014-03-11 at 20:56 #

      Thanks Reuben!. This helps!

    • Martin Brennan 2015-05-18 at 07:07 #

      Thanks Reuben, helped me out too!

    • Jason Judge 2015-05-18 at 12:02 #

      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.

    • Gilles 2015-06-05 at 08:55 #

      Thanks for the help !

      • Jason Judge 2015-06-05 at 10:02 #

        It still amazed me how long some tips stay relevant!

        • Josiah 2020-01-30 at 15:44 #

          Still relevant 🙂

    • hyq 2017-07-26 at 03:28 #

      thank you very much!

  3. chris 2014-01-30 at 01:02 #

    Fyi…this is what is meant by restart explorer:

  4. Stijn de Witt 2014-02-07 at 16:05 #

    Seems it is a known bug in TortoiseGit:

    Note the hint at the bottom of the bug report:
    “Killing the cache process allows the move.”

  5. Ghis 2015-02-06 at 01:25 #

    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.

    • Sigma 2015-09-10 at 09:49 #

      Unlocker is awsome!

  6. emiliano 2015-10-28 at 02:47 #

    try using this

  7. xuser 2018-04-07 at 16:06 #

    I my case, it was Visual Studio code having the locks. I was able to move the folders after closing VS.

  8. GS 2018-06-22 at 12:39 #

    Thanks, this tip was very helpful! (and the fact that you documented it 7 years ago!) I would never have thought of killing explorer.

    • Jason Judge 2018-06-22 at 12:47 #

      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.

  9. bob 2019-06-26 at 15:11 #

    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

Leave a Reply