状況
- 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できるのにサブモジュールだけできない理由がよくわかりません。
根本的な解決方法ではない気がするので誰か教えてください。