Git配置分system、global、local三级,优先级依次升高;用git config --list --show-origin可查看带来源的完整配置,或分别用--system/--global/--local --list查看各层配置。

Git 本身没有 config-list 这个内置命令,但你可以通过组合标准 Git 配置命令,清晰查看当前生效的所有配置项及其作用域(system、global、local)。
用 git config --list --show-origin 查看带来源的完整配置
这是最直接有效的方式,它会列出所有生效的配置项,并在每行开头标出该配置来自哪个文件及作用域:
- /etc/gitconfig → system 级(全系统生效,需 root 权限修改)
- ~/.gitconfig 或 ~/.config/git/config → global 级(当前用户全局生效)
- .git/config → local 级(仅当前仓库生效)
执行命令:
git config --list --show-origin
输出示例:
file:/etc/gitconfig core.autocrlf=input file:/home/user/.gitconfig user.name=John Doe file:/home/user/.gitconfig user.email=john@example.com file:/home/user/myrepo/.git/config core.editor=nvim
按作用域分别查看配置
若想单独确认某一层级的配置(比如排除 local 干扰),可用指定参数过滤:
- 只看 system 级:
git config --system --list - 只看 global 级:
git config --global --list - 只看 local 级:
git config --local --list(在仓库内运行)
注意:如果某层级没有对应配置文件(如未创建 ~/.gitconfig),命令会报错或静默无输出,可加 --get-all 或配合 2>/dev/null 忽略错误。
覆盖宏观策略、固收研究、行业公司深度分析、量化因子、大类资产配置、可转债、市场情绪、政策快评、行业景气度追踪等34项核心研究能力,证券研究员的全能数字助手。
识别哪些配置实际生效(覆盖规则)
Git 配置按优先级从低到高为:system
- global 设置了
user.name=A,local 又设为user.name=B,则当前仓库中生效的是B - 用
git config user.name(不带作用域)会返回当前上下文实际生效的值,即 local > global > system 的第一匹配项
想快速验证某个键的最终值,直接运行:git config --get user.name
查看配置文件路径辅助定位
有时你不确定配置文件是否存在或位置是否正确,可用这些命令确认路径:
- system 文件路径:
git config --system --get-init-path - global 文件路径:
git config --global --get-init-path - local 文件路径就是当前仓库下的
.git/config
再配合 ls -la 检查文件是否存在,能帮你快速排查“为什么配置没生效”这类问题。










