Home > Net >  Problem using two github accounts on the same pc
Problem using two github accounts on the same pc

Time:04-09

I am trying to use github accounts on my pc and I have implemented the solution from Can I log in two different github account in vscode?. The first account was able to push to the correct repo but the commit was registered using the username from the second account not the first one.

When I created a new repo to test the second account it did failed to push with the error

remote: Permission to Taku-chimanaz/dummy_repo.git denied to Code-Upgrade-Tech.
fatal: unable to access 'https://github.com/Taku-chimanaz/dummy_repo.git/': The requested URL returned error: 403

Now it seems like the first account (Code-Upgrade-Tech) is linked to the second account (Taku-chimanaz).

CodePudding user response:

the first account (Code-Upgrade-Tech) is linked to the second account (Taku-chimanaz).

Yes, through the credential manager caching the HTTPS credential (second account / second account token): see git config --global credential.helper

The first account was able to push to the correct repo but the commit was registered using the username from the second account not the first one.

The commit author has nothing to do with the user account pushing said commit.
Its authorship is only determined by the local repository setting: git config user.name / git config user.email.

Using SSH instead of HTTPS would me:

  • registering a different public key, one for each GitHub account.
  • having a ~/.ssh/config file with two Host entries
  • using said Host entries to rename your URL

That is:

# ~/.ssh/config

Host gh1
  Hostname github.com
  User git
  IdentityFile ~/.ssh/mykey1

Host gh2
  Hostname github.com
  User git
  IdentityFile ~/.ssh/mykey2

And:

cd /path/to/repo1
git remote set-url origin gh1:user1/repo1

cd /path/to/repo2
git remote set-url origin gh2:user2/repo2
  • Related