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

相关推荐
摆烂z10 小时前
AI同时完成多个功能(Git WorkTree)
git
___波子 Pro Max.15 小时前
Git Worktree 可视化理解指南
git
happymaker062617 小时前
git使用快速入门
git
不做超级小白17 小时前
从零到可用:在手机上用 Termux + Git + Obsidian 打造稳定同步环境(踩坑全记录)
git·智能手机
凡客丶17 小时前
Git安装与使用保姆教程【超详细】
git
android_cai_niao17 小时前
给Git项目添加多个远程仓库
git·gitee·github
胡小禾18 小时前
多账号下git自动切号
git
zhensherlock18 小时前
Protocol Launcher 系列:Working Copy 提交与同步全攻略
javascript·git·typescript·node.js·自动化·github·js
前端若水18 小时前
Git 全命令超级详细指南
大数据·git·elasticsearch
SiYuanFeng1 天前
新手学Git:如何把本地 Git 项目上传到 GitHub
git·github