首页 > 解决方案 > 如何将 Gitlab 自我管理的子模块连接到 deepsource.io

问题描述

我想将一个 git 子模块连接到 deepsource.io。它说我需要通过 SSH 连接它。主存储库托管在 Github 上,子模块由 Git 实验室自管理(git.server.com)托管。

我必须在哪里粘贴 deepsource.io 的公共 SSH 密钥?我必须在我的帐户或子模块上连接它还是如何连接?

标签: gitgithubgitlabgit-submodulesdeepsource

解决方案


在 deepsource.io 上生成 SSH 密钥后(通过导航到存储库的设置 > SSH 访问 > 生成 SSH 密钥对),复制提供的公钥并将其作为部署密钥添加到 GitLab 子模块存储库(设置 > 存储库 > 部署键)。不要授予对密钥的写权限。

参考:如何在 GitLab 上启用部署密钥

如果您使用 HTTPS URL 来指定子模块(查看.gitmodules存储库根目录中的文件),则需要将它们更改为 SSH URL。为此,您可以

  1. 直接编辑.gitmodules文件:如果文件看起来像这样:
[submodule "screamer"]
    path = screamer
    url = https://git.myserver.com/org/screamer.git

你可以改变它看起来像

[submodule "screamer"]
    path = screamer
    url = git@git.myserver.com:org/screamer.git
  1. 运行如下命令:
git config --local url.git@git.myserver.com:.insteadOf https://git.myserver.com/

这将更改您的.git/config文件,如下所示:

[url "git@git.myserver.com:"]
    insteadOf = https://git.myserver.com/

推荐阅读