20

I have CentOs. I make git and made owner's .git folders group "gitdevelopers". In group "gitdevelopers" add User1 and User2. Now i make git-push and git-pull change from user1 and user2. But users in your computers not work with error:

git.exe pull -v --no-rebase --progress "origin" error: cannot open .git/FETCH_HEAD: Permission denied

Why?

p.s.:And i can connect to server by x-shell with login-password user1 and user2.

few hours later:: I think problem in not right login-password, which git remember.

p.p.s: where git save login-password pairs? I use ssh-protocol.

p.p.p.s.:OK. I have server CentOs with git. On server is two users. And I use TortoiseGit for windows. I configure this so : in each connect system asked login and password for connect to server. And now I wanted know : 1. where is saved this login-password 2. i can permanently saved this pair?

Helen
  • 317
  • 1
  • 2
  • 5
  • Did you try `git config core.sharedRepository true` (on the server, in the .git repos) + chmod as in http://serverfault.com/a/27040/783? – VonC Mar 16 '15 at 09:12
  • What protocol are you using when contacting the remote? https? ssh? – VonC Mar 16 '15 at 11:56
  • 1
    ssh means there is no login/password, only public and private keys stored in `~/.ssh/`(`id_rsa.pub`, `id_rsa`) – VonC Mar 16 '15 at 13:30
  • As long as you keep using "login" and "password", your ssh url won't work. – VonC Mar 16 '15 at 14:08
  • Does this answer your question? [Trying to git pull with error: cannot open .git/FETCH\_HEAD: Permission denied](https://stackoverflow.com/questions/13195814/trying-to-git-pull-with-error-cannot-open-git-fetch-head-permission-denied) – gaganso Jan 19 '20 at 22:21

6 Answers6

64

This worked with me

sudo chown -R $(whoami) .git/
Pablo Papalardo
  • 1,224
  • 11
  • 9
  • It worked well. Can you please explain the logic behind it ? – Tarun Nagpal Jul 10 '20 at 08:25
  • sudo chown=change ownership of directory, -R=make it recursive, meaning of all sub folders and files inside that directory, $(whoami)=get current logged in user, .git/=is the folder where info about git repository is stored, Hence this command will change the ownership of file to current user, so this user can perform commands like "git pull" etc. – Hasnat Safder Oct 27 '20 at 04:09
3

if you are using ubuntu, use sudo key word before.

sudo git pull

if you are using windows, use administrator mode

Mohamed Salman
  • 309
  • 2
  • 9
2

you can check for the permissions on the file,

ls -l /usr/local/Library/Taps/linode/cli/.git/FETCH_HEAD

and

ls -l /usr/local/.git/FETCH_HEAD

Rizwan
  • 3,741
  • 2
  • 25
  • 22
0

Generating a new SSH key pair

ssh-keygen -o -t rsa -b 4096 -C "email@domain.com"

Adding an SSH key to your GitLab account

Copy your public SSH key to the clipboard and paste it into your user account >  SSH Keys 

For Authentication you need to set configuration in ~/.ssh/config as content bellow;

Host domain.com

Hostname domain.com

User git

Port 30001

Preferredauthentications publickey

RequestTTY no

IdentityFile ~/.ssh/id_rsa

You can use commands as; In these command mentioned common variables, replace the related values of those.

Create a new repository

git clone ssh://git@domain.com:port-number/user-name/project-name.git

cd project-name

touch README.md

git add README.md

git commit -m "add README"

git push -u origin master

Push an existing folder

cd existing_folder

git init

git remote add origin ssh://git@domain.com:port-number/user-name/project-name.git

git add .

git commit -m "Initial commit"

git push -u origin master

Push an existing Git repository

cd existing_repo

git remote rename origin old-origin

git remote add origin ssh://git@domain.com:port-number/user-name/project-name.git

git push -u origin --all

git push -u origin --tags

To clone repository:

git clone https://git@domain.com:port-number/user-name/project-name.git

0

this worked for me:

sudo chown -R $ USER: name_repo

note: in my case I had cloned the repository with the root user and then I started using another user

0

Delete the existing solution and doing a git clone solved the issue for me

Sudhir Rao
  • 19
  • 1