Interview Prep/Git & GitHub/Remotes, Collaboration and Pull Requests

You use a personal and a work GitHub account on one laptop.

IntermediateScenarioRemotes, Collaboration and Pull Requests
Answer

Situation read → SSH picks the first matching key, which authenticates as the wrong user.

What I'd do →

  1. Create two keys and add each to its own account.
  2. In ~/.ssh/config:
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes
  1. Clone with git@github-work:ORG/repo.git.
  2. Set the email per directory with includeIf "gitdir:~/work/" in ~/.gitconfig.

Why → The alias selects the key, and IdentitiesOnly stops the agent from offering others.

Interview tip → includeIf avoids committing work code with your personal email.

All Git & GitHub questions Roadmap: Git & GitHub

More on Remotes, Collaboration and Pull Requests