git multiple credential helper

对着背影说爱祢 提交于 2020-01-20 08:10:47

问题


I have multiple remotes in my local git clone. Both of the remotes are using https to connect to git and need different credentials. I am using codecommit and hence the codecommit credential-helper for credentials. Is there a way I can use separate credential helper for different roots.


回答1:


I was able to put the following in my ~/.gitconfig and my AWS CodeCommit and GitLab remotes (in the same repo) were able to successfully fetch.

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

One issue I did have though was: "fatal: unable to access 'https://git-codecommit.us-west-2.amazonaws.com/v1/repos/myrepo/': The requested URL returned error: 403.

I discovered this was due to another "helper = manager" located in another gitconfig when I upgraded my Windows Git install. I ran "git config --list --show-origin" so that I could see which file this was from (file:C:/Program Files/Git/mingw64/etc/gitconfig credential.helper=manager). After commenting the lines out with semicolon ;, the error disappeared. Moving that line into my ~/.gitconfig resolved the issue.

UPDATE:

AWS updated their website with better information on using multiple credential helpers. Here is what my ~/.gitconfig looks like now:

[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

If you are on a Mac and start see this answer on cleaning up git credentials in OS X Keychain



来源:https://stackoverflow.com/questions/53189190/git-multiple-credential-helper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!