Git add errors: Could not open directory: Permission Denied

Viewed 22833

I am using windows 10. When I type the command "git add ." in my Git Bash I keeping getting this message as shown below:

warning: could not open directory 'AppData/Local/Application Data/': Permission denied
warning: could not open directory 'AppData/Local/ElevatedDiagnostics/': Permission denied
warning: could not open directory 'AppData/Local/History/': Permission denied
warning: could not open directory 'AppData/Local/Microsoft/Windows/INetCache/Content.IE5/': Permission denied
warning: could not open directory 'AppData/Local/Microsoft/Windows/Temporary Internet Files/': Permission denied
warning: could not open directory 'AppData/Local/Temporary Internet Files/': Permission denied
warning: could not open directory 'Application Data/': Permission denied
warning: could not open directory 'Cookies/': Permission denied
warning: could not open directory 'Documents/My Music/': Permission denied
warning: could not open directory 'Documents/My Pictures/': Permission denied
warning: could not open directory 'Documents/My Videos/': Permission denied
warning: could not open directory 'Local Settings/': Permission denied
warning: could not open directory 'My Documents/': Permission denied
warning: could not open directory 'NetHood/': Permission denied
warning: could not open directory 'PrintHood/': Permission denied
warning: could not open directory 'Recent/': Permission denied
warning: could not open directory 'SendTo/': Permission denied
warning: could not open directory 'Start Menu/': Permission denied
warning: could not open directory 'Templates/': Permission denied
3 Answers

In case someone else comes here when searching for this error, and they are definitely on the correct path already, this issue may be caused by unsaved files in the working directory - try making sure all files are saved, and closing any IDE that is open

You are running Git subcommand on a unexpected directory.

Most of Git subcommand are path-dependent. In most cases these subcommand treats the current working directory as Git root, and do Git operations inside Git root.

For regular usage, we treat the root directory for code project as Git root. Multiple code project results in multiple folder, and multiple corresponding Git roots. Use current working directory to specify them.

The default current working directory is called Home directory, which is ~ or mostly /home/<user> or /root in *nix, or C:\Users\<user> (non-Administrator) or C:\Windows\System32 (Administrator) in Windows > 7 or C:\Documents and Settings\<user> in Windows <= XP.

If you didn't specify current working directory (with command cd), all the Git operations are operating your home directory. This can be harmful under some situations. Small disaster is just like what you met, big disaster can be something like you accidently uploaded your private file in GitHub or something equivalent after you realized that.

  1. First Go to that path and DELETE the .git repository.(In your File Manager)
  2. Open Git Bash at Required Folder(It means in Folder by clicking right click)
  3. Create .git repository by giving command ($ git init).
  4. By this there is one .git file will be created (.git file will created in your required folder).
  5. Now Check git status. Hurrrrrrrrrrayyyyy!
Related