问题
Using this guide here I have created a work ssh-key (id_rsa_work
) and changed my config
file to
# Personal GitHub account
Host github.com
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
# Work GitHub account
Host github.com-work
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa_work
I have added the work ssh to my work git-repo and I can call
git clone git@github.com-work:user/test.git
and clone it.
The problem is that there is a submodule in test
which I cannot update, calling
git submodule update
throws the error
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@github.com:user/Utils.git' into submodule path 'C:/Users/user/Documents/work/test/Utils' failed
It seems like it tries to pull using my personal setting (git@github.com
) and not the work (git@github.com-work
). I have called git submodule init
and have tried modify the .gitmodule
url to
[submodule "Utils"]
path = Utils
url = git@github.com-work:user/Utils.git
回答1:
I figured it out:
After calling git submodule update
change the URL (for some reason it does not change, eventhough I change the .gitconfig
file) by
(assume you are in the test
folder)
git submodule set-url ./Utils/ "git@github.com-work:user/Utils.git"
git update
cd Utils
git checkout master
来源:https://stackoverflow.com/questions/62769787/make-git-submodule-update-from-specific-host-in-config