一、下载 Git(Windows)
官网下载地址:
👉 https://git-scm.com/download/win
(会自动下载适合 Windows 的版本)
安装时建议保持默认设置,不要乱改
只需要注意 2 个地方:
① 选择编辑器(Editor)
看到 Select Editor 时,建议选择:
👉 Use Visual Studio Code as Git's default editor
(如果你装了 VS Code)
否则保持默认 Vim 也可以。
② 选择默认分支名(Default branch name)
推荐使用:
👉 main
(现在国际默认都是 main)
🧩 二、验证是否安装成功
打开 PowerShell / CMD / Git Bash 任意一个,输入:
git --version
如果显示版本号,就安装成功。
🔧 三、配置 Git 用户名与邮箱(最重要)
⚠️ 注意:
邮箱必须用 GitHub 提供的 noreply 邮箱,避免泄露真实邮箱。
1. 设置用户名(随便写英文昵称)
git config --global user.name "你的GitHub昵称"
例如:
git config --global user.name "searchnee"
2. 配置 GitHub 提供的 noreply 邮箱
例如:
12345678+yourid@users.noreply.github.com
配置命令:
git config --global user.email "xxxx+yourid@users.noreply.github.com"
3. 查看是否设置成功
git config --global --list
应该能看到:
user.name=xxx user.email=xxxx@users.noreply.github.com
🔑 四、配置 GitHub SSH(推荐,免登录)
免密 push 非常方便。
1. 生成 SSH Key
ssh-keygen -t rsa -C "你的noreply邮箱"
一路按 Enter 即可。
生成的位置一般是:
C:\Users\你的用户名\.ssh\id_rsa.pub
2. 复制公钥
打开:
cat id_rsa.pub
复制里面的内容。
3. 添加到 GitHub
路径:
GitHub → Settings → SSH and GPG keys → New SSH key
把公钥粘贴进去 → 保存。
4. 测试连接
ssh -T git@github.com
如果是第一次配置和连接,会提示"The authenticity of host 'github.com(ip地址)' can't be established. XXXX key fingerprint is: (你的key信息)This key is not known by any other names."
Are you sure you want to continue connecting (yes/no/[fingerprint])? 输入【yes】
这个提示是第一次用 SSH 连接 GitHub 时的正常安全提醒,不是错误
含义是:
-
你的电脑 第一次 用 SSH 连接
github.com -
本地还没有保存 GitHub 的服务器指纹(host key)
-
所以 SSH 会提醒你:"你确定这是 GitHub 吗?要不要信任这个服务器?"
这就是一个安全确认步骤,防止你连到假服务器(中间人攻击那种)。
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
如果配置没问题,成功会显示:
Hi username! You've successfully authenticated...
🎉 五、克隆 / Push 测试
克隆仓库:
git clone git@github.com:账号/仓库名.git
提交:
git add .
git commit -m "test"
git push
如果 push 成功,Git 已完全配置好。