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

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:

sudo npm run deploy

其他回答

看起来第一个不工作,因为您的用户没有更改目录的权限,第二个是因为您的根用户没有访问git存储库的正确SSH密钥。

根据您要做的事情,最好是将存储库克隆到另一个目录,或者将当前目录删除,以便您的用户拥有完全访问权限

使用这个命令,它对我有用。

sudo chown -R $USER:。

参考:https://techoverflow.net/2019/05/07/how-to-fix-git-error-cannot-open-git-fetch_head-permission-denied/

在我的情况下,我有一个双启动系统(Windows 10和Linux),项目文件夹在NTFS磁盘上。事实证明,在另一次更新中,Windows 10在其设置中启用了“快速启动”。 在我在Windows中未选中它之后- Linux中的“错误:无法打开.git/FETCH_HEAD:权限被拒绝”消失了。

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

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。

错误:不能打开。git/FETCH_HEAD:权限被拒绝

这对我来说很有用:

默认情况下。git文件夹是隐藏的。 取消隐藏。git文件夹及其子文件夹和文件,并尝试拉请求。