【发布时间】:2013-05-28 08:51:25
【问题描述】:
我有两个 git 身份,一个是个人的,另一个是我的雇主的。
我的工作项目使用了一个子模块,虽然我可以很好地克隆主仓库,但我无法更新子模块。我需要进行什么配置,这样子模块也可以在本地更新而不会出现以下错误?
Fetching origin
From github.com:/work_domain/work_submodule
* branch HEAD -> FETCH_HEAD
error: pathspec 'master' did not match any file(s) known to git.
我的 ~/.ssh 目录中有 2 组 id_rsa 密钥:
id_rsa.pub <= personal ssh key
id_rsa_work.pub <= work ssh key
~/.ssh/配置文件:
#work acccount
Host github-work
HostName github.com
User git (corrected with info from answers)
IdentityFile ~/.ssh/ida_rsa_work
#personal account
Host github-personal
HostName github.com
User git
Identity ~/.ssh/ida_rsa
当我最初成功克隆我的工作存储库时,我使用了调整后的主机映射:
git clone git@github-work:work_domain/repo_name.git
而不是我在工作时通常使用的:
git clone git@github.com:work_domain/repo_name.git
在工作项目 repo 中,.gitmodules 文件当然有官方映射:
[submodule "work_submodule"]
path = work_submodule
url = git@github.com:/work_domain/work_submodule.git
根据以下建议,我将 .gitmodules 属性更新为:
[submodule "work_submodule"]
path = work_submodule
url = git@github-work:/work_domain/work_submodule.git
但是还是不能在本地更新子模块。
【问题讨论】:
-
github ssh 访问总是以“git”作为用户名——因此你的 ssh 配置文件中的“work-username”是错误的
-
您可以在 .git/config 中更改子模块的实际远程。这不会被推送或其他任何东西,只会影响您的本地仓库。
-
用建议和最新错误更新问题