git config的配置全局或局部仓库的参数: local, global, system

发布于:2025-08-13 ⋅ 阅读:(13) ⋅ 点赞:(0)

1. --local: 作用于当前仓库

--local: 这个参数的作用范围是当前仓库。其配置的参数保存在当前 git 仓库下的 .git/config 中,只对当前仓库有效。

示例指令:

git config --local user.name "myNameLocal"
git config --local user.email "1234@xxx.com"

执行完上述指令之后,文件.git/config 中会增加如下两行内容:

在这里插入图片描述

2. --global: 作用于当前用户的全局范围的 Git 仓库

--global: 作用于当前用户的全局范围的 Git 仓库。其配置的参数保存在当前用户下的 ~/.gitconfig 中,只对当前用户有效。

示例指令:

git config --local user.name "myNameGlobal"
git config --local user.email "1234123@xxx.com"

执行完上述指令之后,文件~/.gitconfig 中会增加如下两行内容:

在这里插入图片描述

3. --system: 作用于系统范围内的 Git 仓库

--system: 作用于当前系统范围的 Git 仓库。其配置的参数保存在系统下的 /etc/gitconfig 中,对当前系统中的所有用户有效。注意,修改系统配置通常需要sudo权限。

示例指令:

sudo git config --system user.name "myNameSystem"
sudo git config --system user.email "123412312@xxx.com"

执行完上述指令之后,文件/etc/gitconfig 中会增加如下两行内容:

在这里插入图片描述

4. 注意事项

  1. 这三种配置只配置其中一个就可以正常使用git。笔者一般使用--global参数对git进行配置。
  2. 可以通过git config --list指令进行查看当前的 git 配置.

比如可以使用下列指令查看--local 配置的参数:

git config --list --local

终端输出结果:
在这里插入图片描述

  1. 当存在多个配置时或者当这个三种配置都已经进行配置了,git 对于这三者有如下的优先级:
    local > global > system , 也就是 配置到当前仓库--local的参数优先级最高。

参考链接

[1] 极客教程. Git 修改git config [EB/OL]. https://geek-docs.com/git/git-questions/531_git_resetting_git_config.html, xxxx-xx-xx/2025-08-12.


网站公告

今日签到

点亮在社区的每一天
去签到