🌟 配置全局用户名和邮箱(适用于所有仓库)
步骤 1:配置用户名
打开终端并运行:
git config --global user.name "Your Name"
步骤 2:配置邮箱
git config --global user.email "your-email@example.com"
🔍 注意:
--global
表示此配置对所有仓库有效。如果你希望为某个特定仓库设置不同的用户名和邮箱,可以跳过--global
。
🔧 配置局部用户名和邮箱(只针对当前仓库)
如果你需要为某个特定仓库设置不同的用户名或邮箱:
- 进入该仓库目录:
cd /path/to/your/repo
- 设置仓库的用户名和邮箱:
git config user.name "Your Name"
git config user.email "your-email@example.com"
✅ 验证配置
你可以使用以下命令检查当前的用户名和邮箱配置:
git config --global user.name
git config --global user.email
如果想查看当前仓库的配置信息(局部配置),可以执行:
git config user.name
git config user.email
🧩 其他配置
如果需要查看所有 Git 配置(包括全局和局部配置):
git config --list
这将显示所有配置项(包括用户名、邮箱等信息)。
通过这些配置,你可以确保在提交代码时,Git 会使用正确的身份信息。如果需要更改邮箱或者用户名,只需要执行相应的 git config
命令即可。