🔧 配置 Git 用户名和邮箱
✅ 设置全局用户名和邮箱(推荐)
适用于所有 Git 项目:
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱@example.com"
例如:
git config --global user.name "Alice"
git config --global user.email "alice@example.com"
✅ 设置某个项目的用户名和邮箱(仅对当前仓库生效)
进入你的项目文件夹后执行:
git config user.name "你的用户名"
git config user.email "你的邮箱@example.com"
✅ 查看当前配置
git config --list
输出类似:
user.name=Alice
user.email=alice@example.com
🔁 修改或删除配置(如需更换)
修改只需再次运行 git config
设置新值即可。
删除:
- 删除全局用户名:
git config --global --unset user.name
- 删除全局邮箱:
git config --global --unset user.email
配置ssh
✅ 检查是否生成并添加了 SSH 密钥
执行以下命令检查你是否已有 SSH 密钥:
ls ~/.ssh/id_rsa.pub
如果没有,生成一个:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
这里会弹出几个配置选项,不需要的话可以一路回车
然后添加公钥到 git 服务器:
cat ~/.ssh/id_rsa.pub
添加ssh秘钥到git仓库(例:gitlab)
复制最后生成的秘钥,按步骤将最终生成的秘钥添加进用户设置中