13

I want to delete my git repository (.git folder) created by git on my windows 7 box. It says access denied to .git/refs/header folder.

I open a console with Administrator role, issue command "takeown /F heads /A /R", it still says "ERROR: Access is denied.", neither can i do via GUI security dialog.

Any suggestion?

Regards, Green

Gelin Luo
  • 14,035
  • 27
  • 86
  • 139

1 Answers1

19

An access denied error may mean the file is in use by another process and, for a GIT repository, that seems more likely than a file permissions issue.

(I'm assuming GIT is like SVN where every file in the repository is created by your own account with standard permissions. If that's not the case then I may be wrong.)

  • As a first step, run Process Explorer as Administrator and push Ctrl-F to open a window where you can type the filename and see which processes (if any) have that file open.

    When I say "run as Administrator":

    I don't just mean when logged in as Administrator. Windows 7's UAC means Administrator accounts don't run things with full admin access by default. Right-click procmon.exe and choose the "Run as Administrator" option.

    I assume you're already familiar with this from running the command prompt as admin. If you just changed to an admin account, but didn't use "Run as Administrator" on the command prompt, then that could be why the takeown command failed. The command prompt should say "Administrator:" in its window title if it is properly elevated, unless UAC is off entirely.

  • If one or more processes are listed, confirm the full file path in the list (in case some other file on disk has a similar name).

  • Close any processes which have the file open. Try to close them normally if you can. As a last resort you can end-task them. If it's a process running as another user/account, it might be a service which you can stop.

    (Ensure View->Show Processes for All Users is ticked, then find the process in question via the PID column. If you think it's a service, hover the mouse over it and a tooltip will appear telling you the name(s) of any services it is running.)

  • If you cannot find any process accessing the file, or closing them all still results in an access denied error, and you are definitely trying the deletion from an elevated command prompt, then you might want to try telling Windows to delete the file the next time it is rebooted. You can use the SysInternals MoveFile tool for that.

Leo Davidson
  • 6,093
  • 1
  • 27
  • 29
  • 2
    You are right, there must be some other process locked the folder. When I close my eclipse process, it get removed. I suppose it's locked by eclipse E-Git plugin somehow. It's windows gives misleading information that the file belongs to unknown user and cygwin reports user and groups are ???. – Gelin Luo Dec 29 '10 at 11:06
  • 2
    +1 For me the problem was TGitCache (Toirtoise Git Cache). Killing it solved it. – Julian Aug 23 '11 at 14:12
  • +1 I encountered this while using Visual Studio with its git integration when trying to switch branches. I closed VS and the file went away (it didn't exist in the other branch) and now all is well. Thanks! – Paul Mar 04 '14 at 18:51
  • Git rename --> Access Denied; File Explorer: Rename --> OK – hfrmobile May 05 '14 at 11:41
  • This happened to me when a cygwin session had the folder open (Access denied folder equal to $PWD). Solution is simply navigate out of it `cd ..` or `cd ~` – adam Mar 31 '16 at 13:58
  • I had this issue due to a hanging git process from the Jenkins slave. `ls -la` showed me the following: `drwxr-x--- 1 Unknown+User Unknown+Group 0 Sep 29 13:41 MyDir` – Roman Oct 02 '17 at 13:28
  • Worked like a charm, as it turned out Vim had MERGE_MSG open, nice to have a solution other than re-booting – Dexygen Oct 27 '17 at 13:31