Git - 设置全局用户名和邮箱

环境信息

Git 版本信息:

shell 复制代码
$ git --version
git version 2.33.0.windows.1

设置全局用户名和邮箱

设置全局用户名:

shell 复制代码
$ git config --global user.name "hello"

设置全局邮箱:

shell 复制代码
$ git config --global user.email "1234567890@qq.com"

查看配置

列出配置文件中所有变量及其值,第 16 ~ 17 行是刚刚设置的全局用户名和邮箱:

shell 复制代码
$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=hello
user.email=1234567890@qq.com

配置文件 .gitconfig 位于用户目录(~)中:

shell 复制代码
$ ls -la ~
total 67
drwxr-xr-x 1 Admin 197121     0 Apr 11 10:20 ./
drwxr-xr-x 1 Admin 197121     0 Jul 19  2021 ../
-rw-r--r-- 1 Admin 197121  3356 Mar 22 18:45 .bash_history
-rw-r--r-- 1 Admin 197121    49 Apr 11 10:20 .gitconfig
-rw-r--r-- 1 Admin 197121    20 Apr 11 10:20 .lesshst
-rw-r--r-- 1 Admin 197121    16 Jul 14  2023 .npmrc
-rw-r--r-- 1 Admin 197121 18367 Sep 16  2021 .viminfo
-rw-r--r-- 1 Admin 197121   944 Apr  2 15:20 allegro.jrl
-rw-r--r-- 1 Admin 197121   948 Mar 14 13:42 allegro.jrl,1
drwxr-xr-x 1 Admin 197121     0 Jul 19  2021 cdssetup/
-rw-r--r-- 1 Admin 197121  8465 Jul 19  2021 license_use.log
-rw-r--r-- 1 Admin 197121   609 Aug 11  2021 pad_designer.jrl
-rw-r--r-- 1 Admin 197121   624 Jul 22  2021 pad_designer.jrl,1
drwxr-xr-x 1 Admin 197121     0 Apr  7 11:39 pcbenv/

使用 cat ~/.gitconfig 命令可以查看位于用户目录中的配置文件:

shell 复制代码
$ cat ~/.gitconfig
[user]
        name = hello
        email = 1234567890@qq.com

参考

如何配置 Git 用户名和邮件地址

git-config(1) Manual Page

相关推荐
Franklin10 小时前
VS 版本更新git安全保护问题的解决
git
我是一只代码狗14 小时前
idea中合并git分支
git
我是一只代码狗14 小时前
idea中使用git
git·gitee·github
恋喵大鲤鱼14 小时前
git restore
git·git restore
李少兄15 小时前
Git Commit Message写错后如何修改?已Push的提交如何安全修复?
git·安全
Fireworkitte15 小时前
git stash
git
pe7er1 天前
git submodule简易指南
git
xiaocainiao8811 天前
Python 实战:构建 Git 自动化助手
git·python·自动化
Casia_Dominic2 天前
【三维重建工具】NeRFStudio、3D GaussianSplatting、Colmap安装与使用指南
git·3d·github·点云