求助:如何配置Golang Git仓库的认证凭证

求助:如何配置Golang Git仓库的认证凭证 你好

我正在尝试按照贡献指南(在WSL(Ubuntu)中)设置Go环境以进行贡献, 但在步骤2:为Go Git仓库配置身份验证凭据时遇到了问题。

运行通过 go.googlesource.com 提供的脚本后, 我尝试运行 $ go-contrib-init 并收到以下错误:

git remote -v output didn't contain expected "https://go.googlesource.com/go". Got:

我不确定我是否遗漏了什么。


更多关于求助:如何配置Golang Git仓库的认证凭证的实战教程也可以访问 https://www.itying.com/category-94-b0.html

1 回复

更多关于求助:如何配置Golang Git仓库的认证凭证的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


根据你遇到的错误信息,问题在于你的本地Git仓库没有正确配置指向Go官方仓库的远程地址。go-contrib-init脚本期望你的仓库远程地址包含https://go.googlesource.com/go,但当前配置中没有找到。

首先,检查你当前的Git远程配置:

git remote -v

如果输出中没有包含https://go.googlesource.com/go,你需要添加正确的远程仓库。通常Go贡献需要设置两个远程:

  1. 添加上游仓库(如果尚未添加):
git remote add upstream https://go.googlesource.com/go
  1. 确认origin指向你的fork(如果你已经fork了仓库):
git remote set-url origin https://github.com/你的用户名/go.git
  1. 验证配置
git remote -v

预期输出应该类似:

origin    https://github.com/你的用户名/go.git (fetch)
origin    https://github.com/你的用户名/go.git (push)
upstream  https://go.googlesource.com/go (fetch)
upstream  https://go.googlesource.com/go (push)

如果问题仍然存在,可能需要重新初始化仓库。先克隆官方仓库:

cd /path/to/workspace
git clone https://go.googlesource.com/go
cd go

然后运行认证脚本和初始化命令:

# 运行go.googlesource.com提供的认证脚本
curl -s https://go.googlesource.com/go/+/refs/heads/master/lib/auth/gitcookies/gitcookies.sh?format=TEXT | base64 -d | bash

# 运行贡献初始化
go-contrib-init

确保你的~/.gitcookies文件已正确创建并包含有效的认证凭证。检查文件内容:

cat ~/.gitcookies

如果认证有问题,可以手动设置Git凭证存储:

git config --global credential.helper store

然后执行一次需要认证的操作来缓存凭证:

git fetch upstream

输入你的Googlesource凭据后,凭证会被保存。之后再次运行:

go-contrib-init
回到顶部