错误:无法锁定配置文件 /etc/gitconfig:权限被拒绝

Wiz*_*tan 8 git ubuntu git-config

我对 Ubuntu 操作系统和 Git 还比较陌生。

我已经按照以下链接中提到的说明在 Ubuntu 20.04 上安装了 Git

开始安装 Git

正如下一步提到的,Git 配置分为三个级别

  1. 系统级配置- 适用于每个用户及其在系统上的所有存储库
  2. 全局级别配置- 适用于当前用户及其在系统上的所有存储库
  3. 本地级别配置- 适用于您正在使用的特定存储库

我可以使用 --global 选项更改 git 的全局设置,也可以使用 --local 选项更改 git 的本地设置。但是当我尝试使用 --system 选项更改系统级别上的 git 设置时,我通过运行命令遇到了以下错误git config --system user.name "My Name"

错误: error: could not lock config file /etc/gitconfig: Permission denied

phd*_*phd 12

下面的文件/etc/属于root,必须用root权限编辑:

sudo git config --system user.name "My Name"
Run Code Online (Sandbox Code Playgroud)

但您试图在系统配置中设置您的个人配置。我的建议是:不要这样做,使用您的全局用户配置:

git config --global user.name "My Name"
Run Code Online (Sandbox Code Playgroud)