Windows环境下配置git和github

一、下载 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 已完全配置好。

相关推荐
闲云一鹤14 小时前
Git LFS 扫盲教程 - 你不会还在用 Git 管理大文件吧?
前端·git·前端工程化
砖厂小工18 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
程序员鱼皮18 小时前
又一个新项目完结,我要出海了!
ai·github·开源项目
徐小夕18 小时前
pxcharts-vue:一款专为 Vue3 打造的开源多维表格解决方案
前端·vue.js·github
Moment19 小时前
想要长期陪伴你的助理?先从部署一个 OpenClaw 开始 😍😍😍
前端·后端·github
阿白的白日梦19 小时前
winget基础管理---更新/修改源为国内源
windows
我叫黑大帅19 小时前
前端如何利用 GitHub Actions 自动构建并发布到 GitHub Pages?
前端·面试·github
HelloGitHub21 小时前
这个年轻的开源项目,想让每个人都能拥有自己的专业级 AI 智能体
开源·github·agent
刘发财1 天前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github