Skip to content

Git Config

一句话解释

git config 在系统、全局(用户)或仓库层级设置 Git 选项,控制身份、别名与行为。

用大白话说

git config 是控制 Git 配置的命令。设置分三层:系统(机器上所有用户,在 /etc/gitconfig)、全局(你的用户,在 ~/.gitconfig)和本地(当前仓库,在 .git/config)。更具体的层级覆盖更不具体的。最常见的配置是 user.name 与 user.email(你在提交中的身份)、core.editor(打开提交信息的编辑器)和 init.defaultBranch(新仓库默认分支名)。还可设置别名、更改 diff 算法、配置行尾处理。读取用 git config user.name,设置用 git config --global user.name "Ada",列出全部用 git config --list,取消用 git config --unset。--global 写入用户配置,使设置适用于你的所有仓库。

示例

bash
# Set your identity globally (applies to all repos)
git config --global user.name "Ada Lovelace"
git config --global user.email "[email protected]"

# Set a repo-specific email (overrides global)
git config user.email "[email protected]"

# View a single value
git config user.name        # Ada Lovelace

# List all settings and where they come from
git config --list --show-origin

--global 写入 ~/.gitconfig(你的所有仓库)。不带 --global 则写入当前仓库。--list 显示每项设置。

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表