6

I'm trying to run:

git checkout master

and im constantly getting: fatal:

failed to read object 9466835e6cb608c32ec4bf98b2acfa421fd77d3d: Permission denied

I tried running:

chown -R my-user *

with no help. any suggestions?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Omri Shneor
  • 965
  • 3
  • 18
  • 34
  • Inspect (with `ls -l`) the file `.git/objects/9/466835e6cb608c32ec4bf98b2acfa421fd77d3d` to see its existing owner and mode. If you ran various Git commands with `sudo` it may be owned by `root`. Inspect the `.git/objects/` directory as well for all its subdirectories as some of them may be owned by root. Your `chown -R` is probably going to be a correct solution, except that `*` will not match `.git` and therefore it has not been applied to any of the files within `.git`. – torek Aug 31 '18 at 15:57
  • sudo chown my_user:my_group -R ./.git/ fixed the problem for me. – avatarofhope2 Sep 24 '19 at 17:39

1 Answers1

3

First Try

sudo chmod -R  777 path_to_your_project_folder

If it does not work try below solution.

Try to do this happens sometimes when dangling blobs are left in git history. You can backup your .git folder and run fsck.

$ git fsck --full

Refer this answer for more details

Rahul Sharma
  • 1,393
  • 10
  • 19
  • `777` is the wrong mode. Most internal `.git.` files should be 0444 or 0644 or 0664, and most directories should be 0755 or 0775. (However, Git hooks need to be executable, hence 0755 as well.) If your computer is not shared with anyone, `777` will be OK, but if it *is* shared, you're inviting others to mischief... – torek Aug 31 '18 at 15:53
  • 1
    Had to run `sudo git fsck --full` as still got permission denied without running as root – Oliver Apr 01 '21 at 03:24