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

相关推荐
测试人社区—52721 小时前
你的单元测试真的“单元”吗?
前端·人工智能·git·测试工具·单元测试·自动化·log4j
无限进步_2 小时前
C语言宏的魔法:探索offsetof与位交换的奇妙世界
c语言·开发语言·windows·后端·算法·visual studio
CHANG_THE_WORLD2 小时前
Python列表(List)介绍
windows·python·list
cicada152 小时前
如何在Windows系统下使用Linux环境?
linux·运维·windows
weixin_462446232 小时前
macOS 安装 git-lfs
git·macos
CoderJia程序员甲2 小时前
GitHub 热榜项目 - 日榜(2025-12-7)
git·ai·开源·llm·github
电子_咸鱼2 小时前
【QT SDK 下载安装步骤详解 + QT Creator 导航栏使用教程】
服务器·开发语言·网络·windows·vscode·qt·visual studio code
空空kkk3 小时前
Git版本控制——diff命令
git
克喵的水银蛇3 小时前
Flutter 通用底部导航栏:BottomNavWidget 一键实现样式统一与灵活切换
windows·flutter