本文覆盖Windows/macOS/Linux三大平台高频问题,附终端命令+故障排查思维导图
一、安装前的关键检查
系统与硬件验证
- Windows:
winver
查看系统版本(需Win8+)macOS:sw_vers -productVersion
(建议10.15+)Linux:cat /etc/os-release
(内核≥3.0)避坑重点:内存≥2GB,预留500MB磁盘空间
安装包安全下载
务必从官网获取:
# 官方镜像(国内加速)https://registry.npmmirror.com/binary.html?path=git-for-windows/
二、Windows专项避坑
安装路径陷阱
- ❌ 错误示例:
C:\用户\张三\git
(含中文路径)✅ 正确示例:C:\DevTools\Git
环境变量配置
安装时勾选:
example.com/git-env-opt…
必须选择“Use Git from Windows Command Prompt”
换行符自动转换
核心设置:
# 全局禁用自动转换(推荐开发者)git config --global core.autocrlf false
安装时选择“Checkout as-is”避免乱码
三、macOS避坑指南
彻底卸载Xcode旧版Git
# 删除预装版本sudo rm -rf /usr/bin/git*# Homebrew安装最新版brew install git
SSH密钥权限修复
chmod 700 ~/.sshchmod 600 ~/.ssh/id_rsa # 关键步骤!
四、Linux避坑要点
依赖缺失导致编译失败
Ubuntu/Debian需提前安装:
sudo apt install libcurl4-openssl-dev zlib1g-dev
避免Root操作风险
# 创建专用用户sudo useradd -m gitusersudo -u gituser git clone <repo>
五、必做的四大基础配置
身份信息设置(首次必须!)
git config --global user.name "YourName"git config --global user.email "you@example.com"
代理配置(科学上网场景)
# HTTP代理git config --global http.proxy http://127.0.0.1:7890# 重置命令git config --global --unset http.proxy
六、安装验证四步法
# 1. 验证版本git --version# 2. 检查核心配置git config --list | grep -E "user.name|user.email"# 3. 测试SSH连通性ssh -T git@github.com# 4. 基础功能测试mkdir test-repo && cd test-repogit initecho "# Test" > README.mdgit add . && git commit -m "init"
七、高效工作流优化
常用别名配置
git config --global alias.st statusgit config --global alias.br branchgit config --global alias.ci commit
凭证缓存(避免重复输密码)
# 缓存15分钟git config --global credential.helper cache# 缓存1小时git config --global credential.helper 'cache --timeout=3600'
大文件管理(>100MB需用LFS)
git lfs installgit lfs track "*.psd"
八、高频故障排查表
错误现象 | 解决方案 |
---|---|
fatal: unable to access... SSL_ERROR | git config --global http.sslVerify false |
Permission denied (publickey) | 执行 chmod 600 ~/.ssh/id_rsa |
warning: LF will be replaced by CRLF | 设置 core.autocrlf=false |
git: command not found | 检查环境变量PATH是否包含git路径 |
九、终极排错工具
日志分析
- Windows:
C:\ProgramData\Git\logs
Linux/macOS:/var/log/git/
或安装临时目录网络诊断
# 测试GitHub连通性curl -v https://github.com# 国内镜像替代方案git config --global url."https://hub.fastgit.xyz/".insteadOf "https://github.com/"
资料推荐