Git error: Unable to append to .git/logs/refs/remotes/origin/master: Permission denied

This looks like you ran git as root locally, thus changing ownership on some of the files tracking the location of the origin branch.

Fix the file ownership, and you should be fine:

# run this from the root of the git working tree
sudo chown -R "${USER:-$(id -un)}" .

Let's concentrate on what it's complaining about exactly:

Permission denied error: Cannot update the ref 'refs/remotes/origin/master'.

Before doing recursive mod/ownership changes, traverse your way to that file and fix any permissions that are incorrect.

I think I caused this issue by creating a branch while I was root and then trying to mess with that branch as my user.


In my case I created the files with root permission locally and tried to push the code to remote with local permissions. So I ran this command

$find . -user root

to find out what all files have "root" as owner. And then I changed owner for all the files that are under root to local using following command

$sudo chown parineethat `find . -user root`

Then I was able to push my code from local to remote.

Tags:

Git

Github