0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHubで親リポジトリはcloneできるのにサブモジュールをcloneできないとき

Last updated at Posted at 2025-03-20

状況

  • Windows11で発生
  • 新規で開発メンバーに加わってもらうためOrganizationに招待し、memberのroleを与えた
  • 親リポジトリ(private)とサブモジュール(private)どちらもweb上で開くことができている(アクセス権がある)
  • gitをインストールしSSH認証キーの登録を済ませている
    • ssh -T git@github.comを実行するとHi username!と出てくる
  • git clone <親リポジトリのSSHのURL>で親リポジトリのcloneができている
  • 親リポジトリのルートディレクトリでgit submodule update --init --recursiveを実行してサブモジュールをcloneしようとすると以下のようなエラーが出た
Cloning into 'C:/Users/<ユーザー名>/**/<親リポジトリ名>/<サブモジュール名>'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@github.com:<組織名>/<サブモジュール名>.git' into submodule path 'C:/Users/<ユーザー名>/**/<親リポジトリ名>/<サブモジュール名>' failed
Failed to clone '<サブモジュール名>'. Retry scheduled
Cloning into 'C:/Users/<ユーザー名>/**/<親リポジトリ名>/<サブモジュール名>'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@github.com:<組織名>/<サブモジュール名>.git' into submodule path 'C:/Users/<ユーザー名>/**/<親リポジトリ名>/<サブモジュール名>' failed
Failed to clone '<サブモジュール名>' a second time, aborting

解決方法

SSHではなくHTTPSでサブモジュールを取得した

git config --file .gitmodules submodule.<サブモジュール名>.url https://github.com/<組織名>/<サブモジュール名>.git
git submodule sync
git submodule update --init --recursive

もともと.gitmodulesの内容は

[submodule "<サブモジュール名>"]
	path = <サブモジュール名>
	url = git@github.com:<組織名>/<サブモジュール名>.git

とSSHのURLだったが、SSH認証がうまくいってないためこれをHTTPSのURLに変えることで成功した

おわりに

SSH認証がうまくいってないのは間違いなさそうだが、親リポジトリをcloneできるのにサブモジュールだけできない理由がよくわかりません。
根本的な解決方法ではない気がするので誰か教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?