golang 使用netrc鉴权访问私有仓库

生成token

在gitlab、github上都支持生成https鉴权认证token

编辑 ~/.netrc文件

machine gitlab.com
   login  账户名
   password  你的token
  • 上述machine是指你的gitlab仓库的地址

  • login则为你的gitlab的用户名

  • password就是第一步创建的gitlab访问token

结合如上几种方式,你应该可以完整的解决掉你的go获取私有依赖的问题。

git使用~/.netrc

运行以下命令,让 Git 在需要凭证时,优先去查找系统标准文件(包含 .netrc):

git config --global credential.helper store

注:当配置为 store 且 .netrc 存在时,Git 会优先匹配 .netrc 中的域名配置。

posted @ 2026-05-29 15:05  YueQAQ  阅读(21)  评论(0)    收藏  举报