I have 2 private Git repositories on GitHub: game-engine and game.
I want to have game-engine as a submodule in my game repository. I have created both repositories, and pushed them to GitHub. My remotes are set up using SSH authentication and that works fine.
In both local repositories I have added my private ssh-key like so:
git config --local core.sshCommand "ssh -i <path-to-ssh-key>"
This has always worked for accessing my private remote repositories (e.g. now I can just use push and pull).
I then try to add game-engine as a submodule to game using the SSH url:
git submodule add [email protected]:maltebp/game-engine.git
But I get this error:
Cloning into 'C:/Users/malte/projects/game/game-engine'...
[email protected]: 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 '[email protected]:maltebp/game-engine.git' into submodule path 'C:/Users/malte/projects/game/game-engine' failed
Do I have to pass in the ssh-key manually or something?
I have found very little about this online so I don't if this is something that people rarely do?
As you showed in your setup: you defined the
core.sshCommandonly locally (the--localingit config --local ...), which means that this option is written to the repository-scoped.git/configfile.This configuration file is not taken into account when running
git submodule add ...so the underlyingclonecommand does not use your customizedssh -i <path-to-ssh-key>command.One way to circumvent that is: make that customized available during the
git submodule add ...commandgit -c ...:git -c core.sshCommand "ssh -i <path-to-ssh-key>" submodule add ...GIT_SSHenvironment variable:GIT_SSH="ssh -i <path-to-ssh-key>" git submodule add ...If you want to always use your dedicated ssh key for repos under
github.com/maltebp, you can set up an alias in.ssh/config, then set aurl.<base>.insteadOfto "catch" accesses togithub.com/matebpand rewrite them using that alias.