I've been having this issue for the last couple of days when trying to make, either, a git status or git pull. The repository is hosted on Bitbucket.
Tried several things to make this work (there are some posts related to this on stackoverflow, but they didn't work).
Here is the issue:
user@Host:/repo/$ git status fatal: index file open failed: Permission denied fatal: git status --porcelain failed
If I do a "git pull":
user@Host:/repo/$ git pull remote: Counting objects: 77, done. remote: Compressing objects: 100% (30/30), done. remote: Total 56 (delta 37), reused 41 (delta 22) error: insufficient permission for adding an object to repository database .git/objects fatal: failed to write object fatal: unpack-objects failed
I double checked the local permissions and everything seems to be fine. I have permission to all the files.
Note:
If I use "sudo" everything seem to work as regular, however I don't have any SSH credentials for root on that deployment machine. It makes me think it is an issue with permissions (as the error explains), however: what it could be, if I'm the owner of all the files, including the files inside .git/
Thanks in advance!
Got the same error fatal: index file open failed: Permission denied
by run git status
, and I checked .git/index
by
$ ls -al .git/index
to my surprise, it's
---------- 1 Kjuly staff 768248 Sep 2 11:07 .git/index
I've no idea why & how it changed. Anyway, after I changed it's permission back to 644
by
$ chmod 644 .git/index
git status
works.
Make sure the .git directory and its files/subdirectories are owned and writable by your user. This sounds like the repository was either cloned under a different user account or as root user (e.g. through sudo
).
It does not matter where the remote of the repository is hosted, git status only accesses the local repository.
I had the same issue and was wondering what could be the cause .. looked around and thought what I was doing and what was touching the file system and the working directory - and I had a suspicion that the files were opened by an IDE with some locks, when I performed the merge and changed branches in a terminal git. Closed the IDE, closed the shell, git pull went OK, no error messages. I had no user changes in the system, so I think a file lock or something the IDE was doing "for me" with the git repo behind the scenes were the reason. Hope this helps someone somewhat. If you are experiencing the same issue and want to get to the bottom of it (not just fix it) ask yourself "Who/what can possibly be touching and changing file ownership of my .git and working directory" ? In my case the suspect was Microsoft Visual Studio. I think the remote repo type investigations and operations are just red herrings and wound dressings (or nuclear options) that do not get to the crux of the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With