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

相关推荐
秦jh_1 小时前
【git】企业级开发模型
git
y***54882 小时前
Git在开源项目中的协作
git
老友記7 小时前
git cherry-pick使用
git
练习时长一年8 小时前
git常用命令总结
大数据·git·elasticsearch
hadage23310 小时前
--- git 的一些使用 ---
开发语言·git·python
4***V20216 小时前
GitLab Pages配置
git·gitlab·github
CelineCoding16 小时前
git 处理异常操作
git
E***q53917 小时前
Git版本控制常见问题
git
sulikey1 天前
从入门到精通:如何自己编写高质量的 .gitignore(面向工程实践)
git·gitee·编辑器·gitlab·github·gitignore·gitattributes
青靴1 天前
轻量级 CI/CD:Git Hooks 自动部署 Node.js 应用(CICD-demo)
git·ci/cd·node.js