Windows 上配置 Git 用户名和邮箱

设置 Git 提交所需的用户名和邮箱——安装 Git 后的第一步,不设无法提交。

Windows命令提示符开发Git低风险
运行 git config --global user.name "Your Name" 和 git config --global user.email "you@example.com",然后用 git config --list 检查。

01命令

命令
$ git config --global user.name "Your Name" && git config --global user.email "you@example.com"

02作用说明

Git 会把这份用户名和邮箱写进每一次提交记录,没有设置就无法提交,所以这是装完 Git for Windows 后要做的第一件事。--global 参数写入 %USERPROFILE%\.gitconfig,对你 Windows 账户下的所有仓库生效;以后想对某个仓库单独设置,在该仓库内不带 --global 重新运行即可。邮箱建议与 GitHub/GitLab 账号一致,提交才能正确关联头像和贡献统计。

03风险

风险低风险
使用条件Git for Windows installed (winget install --id Git.Git or git-scm.com)
!注意: 邮箱会永久写入每条提交的历史记录,公开仓库请避免使用私人邮箱。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • First-Time Git Setup (Pro Git book)
    Git Project · vendor-doc · 2026-09-17
    依据: Documents user.name and user.email as the mandatory first-run settings, set with git config --global and verified with git config --list.

最后验证: 2026-09-18 · 分类: 开发者

06相关方案