请帮助我,我试图在我的终端运行这个:

asgard@asgard-A7N8X2-0:~/CollegePortal$ git pull
error: cannot open .git/FETCH_HEAD: Permission denied

那我试试这个

asgard@asgard-A7N8X2-0:~/CollegePortal$ sudo git pull
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

帮帮我,我不明白这个问题。


当前回答

使用实例设置当前用户的权限

$ sudo chown -R <用户名> .git/

其他回答

这里有很多答案,很多建议做咀嚼。 对我来说,将user改为拥有该文件夹的用户(在我的例子中是tomcat)要容易得多,因为所有者可以这样写: Sudo su tomcat 然后做一个 git拉 无需更改权限。我更喜欢这样做,因为我不需要记得在完成操作后重新更改权限。

要找到拥有该文件夹的用户,执行ls -la

注意:不要给所服务的文件夹非sudo写访问权限!

我得到这个,因为我有一个以上的用户帐户在我的盒子。我以用户A的身份登录,在用户B的目录中。用户A没有权限访问用户B的东西。当我意识到我不在文件系统中的位置时,这个错误就有意义了。

当我在做包安装时,我得到:

Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/bin
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/bundler
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/specifications
Fetching gem metadata from https://rubygems.org/.........
error: cannot open .git/FETCH_HEAD: Permission denied

我已经按照这里的步骤更新了bash_profile,添加了一个rbenv shim。

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

但不知什么原因,我把它们删掉了。一旦我取消了注释,我就能够成功地运行bundle install。

sudo chmod -R 777 .git或者如果你想为自己添加rw权限,你可以使用sudo chmod -R +rw .git

如果您还没有将自己添加到拥有.git/的组中,那么您应该这样做。

sudo usermod -a -G $(stat -c '%G' .git) $USER
sudo chmod g+u .git -R
sudo chmod g+u .gitignore
su - $USER

它的作用:

找出拥有.git/的组,并将用户添加到该组。 确保组成员具有与.git/的所有者相同的权限。 为.gitignore重复此操作,您可能需要它 登出并重新登录,以刷新组成员文件权限

如果你最近做了类似的事情(将自己添加到拥有.git/的组中),那么你需要在git拉取期间能够写入.git/FETCH_HEAD之前注销并重新登录。