Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
3 views
in DevOps and Agile by (19.7k points)

Help me please, I am trying to run this in my terminal:

asgard@asgard-A7N8X2-0:~/CollegePortal$ git pull

error: cannot open .git/FETCH_HEAD: Permission denied

Then I try this one

asgard@asgard-A7N8X2-0:~/CollegePortal$ sudo git pull

Permission denied (publickey).

fatal: The remote end hung up unexpectedly

Help me, I don't understand this problem.

1 Answer

+3 votes
by (62.9k points)

If you haven't added yourself to the group that owns .git/, then you should.

sudo usermod -a -G $(stat -c '%G' .git) $USER

sudo chmod g+u .git -R

sudo chmod g+u .gitignore

su - $USER

What this does is it:

  1. finds out which group owns .git/ and adds your current user to that group.

  2. ensures that the group members have the same permissions as the owner has for .git/.

  3. repeats this for .gitignore, which you'll probably need

  4. logs you out and back in to refresh your new group membership file permissions

If you recently did something like this (added yourself to the group that owns .git/), then now you'd have to log out and back in before you'll be able to write to .git/FETCH_HEAD during your git pull.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...