Windows 下 Git 入门指南:从安装、配置 SSH 到加速 GitHub 下载

在国内用 Git,总感觉速度跟蜗牛似的?或者第一次用 SSH 总是连不上 GitHub?这篇文章就来带你从零搞定 Windows 下 Git 的常用配置,包括:

  • Git 安装

  • 配置用户名邮箱

  • 配置 SSH Key 并连接 GitHub

  • 用国内镜像加速 Git clone/pull

  • 命令行与 VS Code 无缝配合

一、Git 安装

✅ 推荐方式:官网直接下

  1. 打开 Git 官网:https://git-scm.com

  2. 点击 "Download for Windows",选择合适版本下载安装即可

  3. 安装过程中,保持默认设置基本就行,但建议把"Use Git from the Windows Command Prompt"也勾上,这样在 cmd 也能用 git。

安装完检查

打开命令行(Win + R 输入 cmd),输入:

复制代码
git --version

输出形如:

复制代码
git version 2.44.0.windows.1

表示安装成功。

二、配置用户名和邮箱(必须配!)

这是 Git 提交记录中显示的作者信息,必须配,否则提交会出错。

复制代码
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱"

比如:

复制代码
git config --global user.name "lee-yeel"
git config --global user.email "[email protected]"

三、生成 SSH Key,连接 GitHub / Gitee

1. 检查有没有现成的 key

复制代码
ls ~/.ssh

如果你看到有 id_rsaid_rsa.pub,可以复用。没有就生成一对。

2. 生成新的 SSH key

复制代码
ssh-keygen -t rsa -b 4096 -C "你的GitHub邮箱"

一路按回车默认,key 会生成在 C:\Users\你的用户名\.ssh\id_rsa.pub 文件中。

3. 添加到 SSH agent

复制代码
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

(⚠️ 如果提示找不到 ssh-agent,可以重启电脑或手动启动 ssh-agent 服务)

4. 把公钥添加到 GitHub

  • 登录 GitHub → Settings → SSH and GPG keys → New SSH key

  • id_rsa.pub 文件的内容复制粘贴进去

    复制代码
    cat ~/.ssh/id_rsa.pub

5. 测试连接

复制代码
ssh -T [email protected]

第一次可能会提示是否继续连接,输入 yes。成功会提示:

复制代码
Hi username! You've successfully authenticated...

四、国内 GitHub 加速方式(clone/pull 太慢的救星)

方式一:替换为镜像 URL(推荐)

国内有不少加速镜像,比如:

  • GitHub 国内镜像(by ghproxy.com):

    原地址:

    复制代码
    git clone https://github.com/user/repo.git

    替换为:

    复制代码
    git clone https://ghproxy.com/https://github.com/user/repo.git
  • GitClone 镜像站方达极客社区

支持 clone 常见项目如:

复制代码
git clone https://gitclone.com/github.com/xxx/xxx.git

也可以通过设置 .git/config 中的 [url "xxx"] insteadOf 来全局加速(进阶用法,稍后可以单独讲)

方式二:使用 Gitee 同步仓库

GitHub 太慢?试试国内的 Gitee(码云),很多项目都有人同步,你也可以手动 fork 一份同步使用。

五、VS Code 里使用 Git 超丝滑

  • 安装 VS Code

  • 装好 Git 后,VS Code 自动集成 git,不用配置

  • 打开项目文件夹,点击左侧的源代码管理图标,就能直接提交、推送、查看 diff,非常方便


总结

现在你已经搞定了:

  • ✅ Git 安装与配置

  • ✅ SSH Key 连 GitHub / Gitee

  • ✅ 国内 clone 加速方法

  • ✅ VS Code 无缝协作

是不是感觉开发体验丝滑多了?如果你经常用 Git 还可以继续研究:

  • 如何配置 ~/.gitconfig 让提交更规范

  • 使用 .gitignore 忽略某些文件

  • 如何用 Git flow 进行多人协作开发

相关推荐
周胡杰2 小时前
鸿蒙接入flutter环境变量配置windows-命令行或者手动配置-到项目的创建-运行demo项目
javascript·windows·flutter·华为·harmonyos·鸿蒙·鸿蒙系统
belldeep4 小时前
如何阅读、学习 Git 核心源代码 ?
git·学习·源代码
我不是秃头sheep5 小时前
Git安装教程及常用命令
git
几道之旅7 小时前
分别在windows和linux上使用curl,有啥区别?
linux·运维·windows
冼紫菜7 小时前
如何在 CentOS 7 虚拟机上配置静态 IP 地址并保持重启后 SSH 连接
linux·开发语言·centos·ssh
一直奔跑在路上8 小时前
【Ansible】基于windows主机,采用NTLM+HTTPS 认证部署
windows·https·ansible
郭逍遥8 小时前
[工具]B站缓存工具箱 (By 郭逍遥)
windows·python·缓存·工具
x-cmd9 小时前
[250512] Node.js 24 发布:ClangCL 构建,升级 V8 引擎、集成 npm 11
前端·javascript·windows·npm·node.js
IT空门:门主10 小时前
本地的ip实现https访问-OpenSSL安装+ssl正式的生成(Windows 系统)
windows·https·ssl
安装虚拟机的老师傅10 小时前
【2025最新】Windows系统装VSCode搭建C/C++开发环境(附带所有安装包)
c语言·windows·vscode·其他