我使用的是 Mac OSX,git 版本 1.8.5.2 (Apple Git-48)
我在 git 存储库中有一个 git 子模块,(据我所知)仅使用一个 git 用户和 rsa key 来克隆、 pull 、提交、 merge 和推送。我还有许多其他用户和 key 对,但 ~/.gitconfig 文件中没有指定其他用户和 key 对。
当该子模块的 Remote 为 https://github
时...等等。它允许我提交正确的用户名和电子邮件,但在推送时,会告诉我:
remote: Permission to some_username/project.git denied to user2.
fatal: unable to access 'https://github.com/some_username/project.git/': The requested URL returned error: 403
但是当我删除 https://...
时远程,而是使用 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a6d637e4a6d637e627f6824696567" rel="noreferrer noopener nofollow">[email protected]</a>:some_username/project.git
远程,它工作正常。
这是 git 或 github 的错误吗?还有其他方法可以解决吗?这两个用户都在其 github 帐户上关联了相关的 rsa key 。
最佳答案
Is this a bug with git or github?
否:使用 https url,您需要在 git 的 url 中添加登录信息才能知道需要什么凭据:
cd /path/to /your/submodule
git remote set-url origin https://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7900160c0b35161e1017391e100d110c1b571a1614" rel="noreferrer noopener nofollow">[email protected]</a>/yourLogin/yourRepo
ssh url 会自动使用您的 key (在 $HOME/.ssh/id_rsa.pub
中),如果 published to your account (并且如果您的帐户是 GitHub 存储库的所有者或合作者)
关于macos - Git 认为我是错误的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24019258/