我的本地 git clone 中有多个 Remote 。两个 Remote 都使用 https 连接到 git 并且需要不同的凭据。我正在使用 codecommit,因此使用 codecommit credential-helper 作为凭据。有没有办法可以为不同的根使用单独的凭证助手。

最佳答案

我能够将以下内容放入我的 ~/.gitconfig 并且我的 AWS CodeCommit 和 GitLab Remote (在同一个 repo 中)能够成功获取。

[credential]
    helper = !aws --profile myusername codecommit credential-helper $@
    helper = manager
    UseHttpPath = true

我确实遇到的一个问题是:"fatal: unable to access 'https://git-codecommit.us-west-2.amazonaws.com/v1/repos/myrepo/': The requested URL returned error: 403.
我发现这是由于在升级 Windows Git 安装时位于另一个 gitconfig 中的另一个“helper = manager”。我运行了“git config --list --show-origin ”,以便我可以看到这是来自哪个文件( file:C:/Program Files/Git/mingw64/etc/gitconfig credential.helper=manager )。用分号 ; 注释掉这些行后,错误消失了。将该行移动到我的 ~/.gitconfig 中解决了这个问题。

更新:

AWS updated their website with better information on using multiple credential helpers 。这是我的 ~/.gitconfig 现在的样子:
[credential "https://git-codecommit.us-west-2.amazonaws.com"]
    helper = !aws codecommit credential-helper --profile myusername $@
    UseHttpPath = true
    ; NOTE: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-https-windows.html#setting-up-https-windows-credential-helper
    ; Setup username/password: https://console.aws.amazon.com/iam/home?#/users/matt?section=security_credentials
[credential]
    helper = manager

如果您使用的是 Mac 并开始在 cleaning up git credentials in OS X Keychain 上查看此答案

关于git 多凭证助手,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53189190/

10-13 09:01
查看更多