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

相关推荐
Kiri霧8 小时前
Git入门
git
Nejosi_念旧9 小时前
git报错解决:ssh: connect to host github.com port 22: Connection refused
git·ssh·github
你的人类朋友10 小时前
说说git的变基
前端·git·后端
程序设计实验室11 小时前
在Windows上将git与ssh-agent搭配使用,再也不用输入git密码了
windows·git
Clownseven11 小时前
Gitea Webhook教程:实现git push后自动部署更新网站 (CI/CD入门)
git·ci/cd·gitea
兔老大RabbitMQ12 小时前
git pull origin master失败
java·开发语言·git
码农小白-RMS20 小时前
cursor-执行git指令(vscode同理)
git
爱喝矿泉水的猛男1 天前
Git Commit 提交信息标准格式
git·commit
℘团子এ1 天前
git中,将新项目推送到新建的远程仓库
git
gitboyzcf1 天前
Git 常用命令
前端·git·后端