1

I have two github accounts, which I'll call ActOne and ActTwo, with emails which I'll call em@one.net and em@two.net. I need to switch off between the two accounts, but I can't get the second account to work.

My current project uses the ActTwo account. When I say git push, I get this error message:

remote: Permission to ActTwo/Tools.git denied to ActOne.
fatal: unable to access 'https://github.com/ActTwo/Tools.git/': The requested URL returned error: 403

I don't know why it's trying to use ActOne instead of ActTwo. My current project's .git/config file looks like this:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = https://github.com/ActTwo/Tools.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
        email = em@two.net
        name = ActTwo
[credential]
        helper = osxkeychain

My ~/gitconfig file looks like this:

[color]
        ui = auto
[filter "lfs"]
        smudge = git-lfs smudge %f
        required = true
        clean = git-lfs clean %f
[credential]
        helper = osxkeychain

It used to have this, but I removed it in a vain attempt to fix the problem:

[user]
        email = em@one.net
        name = ActOne

Addendum:

The problem seems to be because my credential helper (osxkeychain) has associated ActOne to the github URL. I added a second entry to Keychain Access for the other account, but it doesn't work. And the reason it doesn't work is that the "Access Control" tab doesn't have an entry for git-credential-osxkeychain. And I can't add one, because the actual application is inside my xCode application bundle, and there isn't any way that I can find in KeychainAccess to go inside an application bundle. Is this the right approach? Does anyone know how to do this?

kostix
  • 51,517
  • 14
  • 93
  • 176
MiguelMunoz
  • 4,548
  • 3
  • 34
  • 51

2 Answers2

4

I don't know why it's trying to use ActOne instead of ActTwo.

Because your credential helper (osxkeychain) has associated ActOne to the github URL.

Open your keychain access, search for github.com related file->and edit credentials there.
See "Updating credentials from the OSX Keychain".

https://help.github.com/assets/images/help/setup/keychain-access.png

If you have already a credential (that you need) associated with that HTTPS URL, switch to an SSH URL: as described here, you can manage multiple accounts that way.


The OP MiguelMunoz adds in the comments:

I had to do a lot to fix this.

  • I had to remove the GitHub entries from my Keychain.
  • I had to set local GitHub user and email using git config user.email and git config user.name.
  • I had to delete the user and email from ~/.gitconfig.
  • I had to set up two identities in my ~/.ssh/config file.
  • I had to set the remotes to use the new identity by using git remote --set-url.
  • And I had to add IdentitiesOnly yes to each identity in the ~/.ssh/config file.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yes, I have a github.com entry in my keychain for ActOne. But I can't just change it to ActTwo, because I need to use both accounts. I've added one for ActTwo, but I don't know how to add git-credential-osxkeychain to the new one. I have updated my original post. – MiguelMunoz Nov 09 '18 at 09:29
  • 1
    @MiguelMunoz A credential helper would only associated *one* account per user. You can use an SSH URL in order to associate multiple accounts: https://stackoverflow.com/a/12066973/6309. I have edited my answer. – VonC Nov 09 '18 at 09:35
  • Thank you. For the record, I had to do a lot to fix this. I had to remove the github entries from my Keychain. I had to set local github user and email using `git config user.email` and `git config user.name`. I had to delete the user and email from `~/.gitconfig`. I had to set up two identities in my `~/.ssh/config` file. I had to set the remotes to use the new identity by using `git remote --set-url`. And I had to add `IdentitiesOnly yes` to each identity in the `~/.ssh/config` file. – MiguelMunoz Nov 17 '18 at 07:28
  • @MiguelMunoz Thank you for this feedback: I have included your comment in the answer for more visibility. – VonC Nov 17 '18 at 07:32
0

I had the same problem, and just figured it out. In the key chain I had the 2 github entries - and just deleted the problematic one. The next time I tried to push the relevant repository it asked for the password and Email account again. That created the new entry the right way. Hope this helps someone.

lolu
  • 370
  • 4
  • 20