跳转至

这是一份为你整理的 Markdown 文档。你可以直接将以下内容复制到一个文本文件中,将其重命名为 Git安装与配置指南.md,之后随时可以查阅。


Git 2.56.0 Windows 安装与配置全记录

本文档记录了 Git 2.56.0 在 Windows 系统下的完整安装步骤、推荐选项,以及安装后遇到的环境配置、历史遗留问题清理和终端避坑指南。

一、 安装向导逐项指南

在运行 Git-2.56.0-64-bit.exe 时,各项设置推荐如下:

1. 选择组件 (Select Components)

  • [x] Windows Explorer integration -> Open Git Bash here(必选,方便右键打开)
  • [ ] Windows Explorer integration -> Open Git GUI here(可不选,自带 GUI 很少用)
  • [x] Git LFS(大文件支持,必选)
  • [x] Associate .git* configuration files(关联配置文件,必选)
  • [x] Associate .sh files to be run with Bash(必选)
  • [ ] Check daily for Git for Windows updates(不建议勾选,避免每天弹窗)
  • [ ] Add a Git Bash Profile to Windows Terminal(可选,若常用 Win11 终端建议勾选)
  • [x] Scalar(保持默认勾选)

2. 开始菜单目录 (Select Start Menu Folder)

  • 保持默认 Git,不要勾选 Don't create a Start Menu folder。占用极小,方便搜索与卸载。

3. 默认编辑器 (Choosing the default editor)

  • 绝对不要选 Vim! 初学者进去可能连怎么退出都不知道。
  • 推荐下拉选择:Visual Studio Code。
  • ⚠️ 注意:千万不要选带 Insiders 字样的版本(那是内测版,如果你没装会导致 Next 按钮变灰)。
  • 保底选项:Notepad(Windows 记事本)。

4. 初始分支名 (Initial branch name)

  • 选择:Override the default branch name for new repositories
  • 填入:main(与 GitHub/GitLab 保持一致,避免后续推送麻烦)。

5. 环境变量 (Adjusting your PATH environment)

  • 选择第二项:Git from the command line and also from 3rd-party software (推荐)。
  • 这样可以在 CMD、PowerShell 和 VS Code 终端里直接使用 git 命令。

6. SSH 可执行文件 (Choosing the SSH executable)

  • 选择第一项:Use bundled OpenSSH(开箱即用,最省心)。

7. HTTPS 传输后端 (HTTPS transport backend)

  • 选择第二项:Use the native Windows Secure Channel library(使用 Windows 证书库,避免公司内网/代理证书报错)。

8. 换行符转换 (Line ending conversions)

  • 选择第一项:Checkout Windows-style, commit Unix-style line endings(Windows 系统标准推荐)。

9. 终端模拟器 (Terminal emulator)

  • 选择第一项:Use MinTTY(Git Bash 标配,窗口可调节,支持非矩形选择)。

10. git pull 默认行为

  • 保持默认:Default (fast-forward or merge)。

11. 凭据助手 (Credential helper)

  • 保持默认:Git Credential Manager(自动记住密码/Token)。

12. 额外选项 (Extra options)

  • [x] Enable file system caching(必选,大幅提升 Git 运行速度)
  • [ ] Enable symbolic links(强烈建议不勾选,普通开发者勾选极易踩坑)

13. 完成安装 (Completing the Git Setup Wizard)

  • 勾选 Launch Git Bash,点击 Finish。

二、 安装时常见问题排查

问题:在“选择默认编辑器”界面,选了 VS Code 但 Next 按钮是灰色的?

  • 原因:误选了 Visual Studio Code Insiders(内测版)。安装程序找不到该版本的安装路径,因此无法继续。
  • 解决:下拉菜单找到没有 Insiders 字样的 Visual Studio Code 即可。

三、 安装后验证与初始化配置

安装完成后,打开 Git Bash(或在终端),输入以下命令验证:

git --version
# 显示 git version 2.56.0.windows.1 即为成功

配置全局身份信息(只需做一次):

git config --global user.name "你的名字"
git config --global user.email "你的邮箱@example.com"

四、 查询配置与清理历史遗留问题

1. 查询全局配置

输入以下命令查看当前生效的所有配置:

git config --global --list

2. 问题发现与修复

在查询结果中,发现了一条带有 .workbuddy 路径的历史凭据配置(通常由某些 AI 辅助工具自带便携版 Git 遗留): credential.helper=!"C:/Users/.../.workbuddy/.../git-credential-manager.exe"

这可能导致推代码时报错。我们需要清理并重新指向 Git 官方的凭据管理器:

1
2
3
4
5
# 1. 删除旧的凭据助手配置(注意 --global 拼写,不要漏掉 l)
git config --global --unset credential.helper

# 2. 重新设置为标准的管理器
git config --global credential.helper manager

再次输入 git config --global --list,确认 credential.helper=manager 即可。


五、 终端使用避坑指南

在 Windows 终端(如 Git Bash、MSYS2)里,绝对不要习惯性使用 Ctrl+V 粘贴命令!

  • 报错特征:如果你看到类似 bash: $'\026': command not found 或 bash: $'\302\226git': command not found。
  • 原因:Ctrl+V 在终端里是“插入特殊控制字符”的意思,且从网页复制命令时经常会带入“隐藏的特殊空格”(\302\226)。
  • 解决方案:
  • 在终端里手动敲入命令(最稳妥)。
  • 如需粘贴,请使用鼠标右键点击选择 Paste,或使用快捷键 Shift + Insert。