deepwzh的技术笔记
  • Golang
  • Python
  • Cpp
杂项
前端开发
  • 计算机网络
  • 操作系统
  • 数据库
云原生
Devops
AIGC
关于作者
  • Golang
  • Python
  • Cpp
杂项
前端开发
  • 计算机网络
  • 操作系统
  • 数据库
云原生
Devops
AIGC
关于作者
  • 杂项
  • Windows UI 自动化方案调研 (2026)v2
  • Nginx
  • 首页
  • Protobuf
  • 学习资料
  • 杂项
  • Ldap
  • 编译原理
  • 分布式

    • 分布式
    • Raft 算法
  • 开发工具

    • 开发工具
    • cloc
    • Vscode
    • 工具箱
    • Visual Studio

      • Visual Studio
      • C++ 相关
      • Visual Studio 基本知识
  • 软件设计

    • 软件设计
    • MVC
    • 领域驱动设计
    • PO、DO、DTO、VO
    • 高内聚低耦合
  • 消息队列

    • 消息队列
    • Celery
    • Kafka
    • RabbitMQ
  • 设计模式

    • 设计模式
    • 控制反转和依赖注入
    • 七大原则
  • 网络安全

    • 网络安全
    • 请求签名
    • CSRF
    • XSS
  • 版本管理工具

    • 版本管理工具
    • Git

      • Git
      • Git get 私有仓库报错
      • Github 加速
      • Clone
      • Git pull 出现 hint 时的解决方案
      • 修改提交记录的作者信息
      • Git mergr
  • 组成原理

    • 组成原理
    • CPU

Git get 私有仓库报错

当安装一个私有库的时候,会报错,比如

go: gitlab.xgjoy.org/demo/demo@latest: module gitlab.xgjoy.org/demo/demo: git ls-remote -q origin in /home/user00/go/pkg/mod/cache/vcs/: exit status 128:
        fatal: could not read Username for 'https://gitlab.xgjoy.org': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

这是因为,go get 请求仓库是,默认采用 https 的方式,即使本地添加了 gitlab 的 ssh 的免密,还是 https 方式还是无授权的,因此,有以下解决方案:

  1. 将 https 转为 ssh 方式
git config --global url."ssh://[email protected]".insteadOf https://gitlab.xgjoy.org

或在~/.gitconfig 中添加下列数据

[url "ssh://[email protected]"]
         insteadOf = https://gitlab.xgjoy.org
  1. HTTPS 增加授权
git config --global url."https://gitlab-ci-token:[email protected]".insteadOf https://gitlab.xgjoy.org

这个 token 可以从 gitlab 上申请一个只读的 token

或在~/.gitconfig 中添加下列数据

[url "https://gitlab-ci-token:[email protected]"]
         insteadOf = https://gitlab.xgjoy.org
Prev
Git
Next
Github 加速