Git 安装闭坑指南(仅 Windows 环境)

💻 Git 安装闭坑指南(仅 Windows 环境)

适用人群 :刚开始用 Git 的 Windows 用户;重新配置开发环境的程序员;不想踩坑的团队小伙伴
目标:快速、稳定地安装 Git,在各种常见场景下避免"下载不了、命令用不了、编码乱码、权限错乱"等问题。


🧩 安装前准备

✅ 1. 确保没有老版本冲突

场景案例

你装过某些 IDE(如 VS Code、SourceTree)或 Git 客户端(如 TortoiseGit),它们可能已经偷偷装了 Git,路径可能乱七八糟。

解决办法

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

    bash 复制代码
    where git

    如果显示多个路径,比如:

    复制代码
    C:\Program Files\Git\bin\git.exe
    C:\Users\zhichao\AppData\Local\Programs\Git\cmd\git.exe

    ➤ 建议卸载所有 Git 版本,并手动删除这些目录,重新干净安装。


🧰 推荐安装方式

✅ 2. 下载推荐地址(避开镜像慢/官网连不上)

下载 Git-2.x.x-64-bit.exe 安装包,不要用 Windows Store 版本(它权限有问题且难以配置)。


🛠️ 安装步骤推荐配置(全图形界面,点 Next 的时候注意这几项)

✅ 3. 安装时重点设置项(别一股脑全默认)

步骤 选项 推荐选择 理由
1 Adjusting PATH Git from the command line and also from 3rd-party software 让所有终端(如 CMD/Powershell)都能用 git 命令
2 Configuring line ending conversions Checkout as-is, commit as-is 防止 Windows/Linux 来回换行符转换导致代码 diff 混乱
3 Choosing HTTPS transport backend Use the OpenSSL library 支持更多 HTTPS 地址,兼容 GitHub 等平台
4 Configuring the terminal emulator Use MinTTY (the default terminal) 更好看的终端界面,支持复制粘贴
5 Default editor used by Git 推荐选择 Visual Studio Code(或你常用的编辑器) git commit 等会自动调用

❗ 安装后常见问题与解决方案

🧨 问题1:安装完成后 git 命令无效

场景

输入 git --version 提示 'git' 不是内部或外部命令

解决办法

  • 可能是环境变量未添加成功。

  • 手动添加系统环境变量:

    控制面板 → 系统 → 高级系统设置 → 环境变量 → 系统变量 Path → 加入:

    复制代码
    C:\Program Files\Git\cmd

🧨 问题2:Git Bash 中文乱码 / 文件名乱码

场景

中文显示为乱码,或 git status 中文文件名显示问号。

解决办法

  • 修改默认编码:

    bash 复制代码
    git config --global core.quotepath false
    git config --global gui.encoding utf-8
    git config --global i18n.commitencoding utf-8
    git config --global i18n.logoutputencoding utf-8
  • 修改 Git Bash 字体:

    • 打开 Git Bash → 右键标题栏 → Options → Text → Font → 选择支持中文的字体如 Consolas新宋体

🧨 问题3:克隆 GitHub 项目报错,SSL 问题

报错

复制代码
SSL certificate problem: unable to get local issuer certificate

解决办法

执行以下命令绕过验证(仅限临时使用):

bash 复制代码
git config --global http.sslVerify false

长期解决方案

确保安装的是带 OpenSSL 的 Git 版本;不要在公司网络下抓 GitHub,可以考虑用 VPN 或离线镜像克隆。


🧨 问题4:拉取/提交速度极慢 or 403 报错

场景

  • clone GitHub 仓库非常慢甚至超时
  • 报错 403 Forbidden

解决办法

  1. 用 SSH 替代 HTTPS,速度快且免登录:

    配置 SSH 密钥

    bash 复制代码
    ssh-keygen -t rsa -C "you@example.com"

    然后将 ~/.ssh/id_rsa.pub 内容复制到 GitHub SSH Keys 页面。

  2. 使用加速镜像工具(如 ghproxy.com):

    bash 复制代码
    git clone https://ghproxy.com/https://github.com/xxx/yyy.git

🎯 验证安装是否成功

bash 复制代码
git --version
git config --list
git clone https://github.com/git/git.git

如果能看到版本号、配置项、并顺利 clone 项目,说明一切正常 ✅。


🎁 附加工具推荐

工具 说明
TortoiseGit Windows 下最强图形 Git 工具
GitHub Desktop GitHub 官方客户端,适合新手
Fork 专业级 GUI 工具,轻量好用
GitLens (VSCode 插件) 让 Git 提交历史、blame 更清晰
相关推荐
来自大山深处的Doge_12 小时前
解决Git提交更新更改时出错: detected dubious ownership in repository at ...
git
leazer14 小时前
Flutter Windows 构建失败:.plugin_symlinks 符号链接异常的排查与修复
windows·flutter
嵌入式爱好者hsw15 小时前
Git 部署本地仓库
git
大貔貅喝啤酒15 小时前
基于Windows下载安装Android Studio 3.3.2版本教程(2026详细图文版)
android·java·windows·android studio
音视频牛哥16 小时前
大牛直播SDK(SmartMediaKit)Windows平台RTSP/RTMP直播播放SDK集成说明(C++版)
windows·音视频·实时音视频·windows rtsp播放器·windows rtmp播放器·超低延迟rtsp播放器·超低延迟rtmp播放器
C137的本贾尼16 小时前
Git基本操作(三):版本回退,坐上“时光机”
git
Irene199116 小时前
Windows 11 WSL Ubuntu 环境:实际安装 Hive 踩坑实录
hive·windows·ubuntu
console.log('npc')17 小时前
Windows 11 → WSL2 → Ubuntu → Docker → Codex → Sub2API
windows·ubuntu·docker
ylifs17 小时前
目的驱动式Git用法
git
ID_1800790547317 小时前
企业级实战:淘宝铺货核心API接口说明(含JSON返回)
windows