Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git multiple credential helper

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.

like image 568
Sunil Kumar Mohanty Avatar asked Nov 07 '18 12:11

Sunil Kumar Mohanty


1 Answers

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

like image 163
mdiehl13 Avatar answered Oct 05 '22 23:10

mdiehl13