1

I find GitHub identities to be very confusing and I regularly struggle with them.

Today, my issue is that I've joined another org's GitHub repository as Owner, but I can't pull from my computer. Although, for a different org, it works properly.

[email protected]:DNA-PC/RepoA.git (✅ pull works, uses "DNA-PC" GitHub account)
[email protected]:NEW_ORG/RepoB.git (❗️ pull fails, uses "DNA-PC" GitHub account)
[email protected]:OLD_ORG/RepoC.git (✅ pull works, uses "DNA-PC" GitHub account)
[email protected]:ANOTHER_OLD_ORG/RepoD.git (❗️ pull fails, uses "Vadorequest" GitHub account)
[email protected]:Vadorequest/RepoE.git (✅ pull works, uses "Vadorequest" GitHub account)

enter image description here

I can't figure out why it doesn't work for the new Org, where I have Owner permissions on all repos. Also, I've noticed by re-trying all my account that another old org isn't working anymore either.

To me, things could be simple:

  • I have 2 different GitHub accounts (Vadorequest, DNA PC)
  • Each has access to different repositories
  • Each should be able to pull all repositories they have access to, and SSH keys are proof of identity

So, how is it possible that I can fetch from RepoA and RepoC but not from RepoB? They should all be verified using the same SSH key.

I had to setup "complicated" stuff to make my 2 identities work:

  • Add several RSA identities in ~/.ssh, one for each GitHub Account (Vadorequest, DNA PC)
  • Add some SSH config with multiple hosts

~/.ssh/config

Host personal-github
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_personal

Host dna-pc-github
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_dna-pc-pro

"complicated": I don't understand how it works, and had to follow blindly some tutorials to have something working, and had to change the format of that multiple times, because each variation had its own issues... (e.g: WebStorm not able to use "Open on GitHub", etc.)

I'm looking for an explanation as to why this setup doesn't work, and what should be the best practice for this setup in 2023.

enter image description here

1
  • What are the remotes for these repos? git remote -v will tell you. Commented Aug 21, 2023 at 19:15

1 Answer 1

1

Following this article, here is my solution: https://gist.github.com/Vadorequest/39315e71dc31b92087aeedca6fdec0df

I made a Gist, as it makes it easier to read.

This solution leans towards simplicity:

  • No need to use a different origin for each repository
  • I can simply copy/paste what GitHub gives me, when doing git clone for a new repo
  • It handles all the shared config in shared files, and each GitHub user has its own configuration (different name/email, PGP key, etc.)
  • I added a rule that makes my former way of writing backward-compatible (to avoid having to update all my existing repos for DNA PC)

I did encounter an issue due to my existing SSH keys (SHA), somehow my personal SSH key wouldn't let me log in using this setup (issued in 2018), but using a brand new SSH keys (ed25519) fixed it (I guess it's related to the security emails GitHub sent me months ago...).

While @VonC answer was interesting, it didn't solve the issue with repeating the same setup for each local repository, which was a real pain for me (and same when cloning).

This answer assumes a directory folder structure such as:

  • ~/dev/vadorequest
  • ~/dev/dna-pc
  • ~/dev/unlyEd

This made it easier to organize everything. Each folder name should match the GitHub user used to perform Git pull/push operations. (but not necessarily, in my case unlyEd folder uses Vadorequest GitHub user, the identity being handled through ~/.gitconfig)

Sign up to request clarification or add additional context in comments.

1 Comment

Nice combination of insteadOf (URL rewrite) and includeIf (config conditional include). I have updated my answer to be complete. Upvoted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.