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

相关推荐
int WINGsssss13 小时前
Git使用
git
用户07605303543815 小时前
Git Revert:安全移除错误提交的方式
git
Good_Starry1 天前
Git介绍--github/gitee/gitlab使用
git·gitee·gitlab·github
云端奇趣1 天前
探索 3 个有趣的 GitHub 学习资源库
经验分享·git·学习·github
F_D_Z2 天前
【解决办法】git clone报错unable to access ‘xxx‘: SSL certificate problem:
网络·git·网络协议·ssl
等风来不如迎风去2 天前
【git】main|REBASE 2/6
git
艾伦~耶格尔2 天前
IDEA 配置 Git 详解
java·ide·git·后端·intellij-idea
云兮杜康2 天前
IDEA中用过git之后文件名颜色全变红
java·git·intellij-idea
睡不醒的小泽2 天前
git merge 和 git rebase
git
艾伦~耶格尔2 天前
Git 下载及安装超详教程(2024)
git·gitee·码仓