【Github】解决 git pull不能拉取 HTTP协议的 Git项目

老问题,新答案

摘要

本文的内容是要解决git使用过程中遇到的错误

话题范围

  • Git 使用 HTTPS协议
  • 适用人群:MacOS和Windows用户
  • Proxy的设置

笔者偏好

在协议的选择上,个人推荐HTTPS,因为https协议方便设置代理。
外文:SSH和HTTPS的优缺点对比


设置了代理的时候,会出现这个错误,网络上给出的解决方案(这个方案不合理):

反驳网络上给出的解决方案

条目 代码 解释
取消http.proxy git config --global --unset http.proxy 我的网络直接连接github服务器有问题才配置的代理,unset proxy是本末倒置。
取消ssl校验 git config --global http.sslVerify false ssl是HTTPS协议的内容,取消SSL校验,那等于是历史倒退,IT人不能开历史倒车,思想不能滑坡。

于是,科学的解决方案是:

通用解决方案

  1. 检查 .gitconfig,是否有无效的Http.proxy, https.proxy
  2. Linux以及MacOS用户:检查http_proxyhttps_proxyall_proxy
  3. Windows用户额外检查系统环境变量:http_proxyhttps_proxyall_proxy
  4. 检查 git remote -v 是否添加了https的origin项目地址。
  5. git remote add origin https://github.com/slankka/xxxx.git

安全话题

  • https://username:password@github.com/,这样会暴露自己的明文密码或者AccessToken,是不太好的方式。

更新凭据管理器

Windows 用户使用凭据管理器 设置密码
MacOS 用户适用钥匙串

这个方法适用人群

  • 企业用户
  • 学生、个人用户
    凭据管理器
    钥匙串

如果仍旧认证失败

  • 取消缓存的git密码 git config --unset credential.helper或者 git config --system --unset credential.helper
  • 如果密码更换过,去Windows凭据管理器,更新https协议的git密码。
posted @ 2021-09-07 10:29  一杯半盏  阅读(8813)  评论(0编辑  收藏  举报