7

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.

Eimantas
  • 48,927
  • 17
  • 132
  • 168

2 Answers2

5

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

Jason
  • 9,408
  • 5
  • 36
  • 36
mdiehl13
  • 472
  • 6
  • 19
  • 1
    One thing to add for Mac: If you somehow have an old entry in "Keychain Access" (Mac key manager), remove it to get everything working properly. – Jamie Jackson Nov 26 '19 at 15:54
0
  • Create one store file for each username.
touch ~/.username-credentials
  • Locally configure each repository with its appropriate store file.
git config --local credential.helper 'store --file ~/.username-credentials'

More about

Git - Credential Storage

HeptaDecane
  • 11
  • 2
  • 3