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 已完全配置好。

相关推荐
miofly4 小时前
Inkling 2 Small 发布,基准测试大幅超越前代但不敌同级对手
开源·github
dong_junshuai5 小时前
每天一个开源项目#153 LZ4:用块边界和有序并行换取低延迟
github
Qiongkura6 小时前
开源自荐:CodeYear:把本机 Git 历史变成年度代码手账(本地优先 · 零上传 · 已上 PyPI)
github
用户8351414049496 小时前
我把 claude-mem 跑了一遍:值得学的地方和踩到的坑
github·claude
QuZhengRong7 小时前
【Luck‑Report】 AI 智能报表助手 + RAG 知识库 + 报表引擎 V2.0.9 更新
github·agent·报表·开源项目·数据可视化
百事牛科技7 小时前
Excel的三种密码:防看、防存、防乱改,各管各的
windows·excel
全栈陈序员8 小时前
Git】从入门到精通(八)—— git log:查看提交历史
大数据·git·elasticsearch
一条Go9 小时前
能力套餐:菜单、权限、开通范围怎么拆成三层而不打架
后端·github·saas
WeWorker9 小时前
浏览器 Agent 的两种宿命:像素派和工具派
github
GitHub实测笔记9 小时前
hyperfine 本机实测:2.96MB 上 bat 开高亮中位数 2.39s、cat 3.0ms(约 870 倍);v2 默认不走 shell
github