Skip to content

Instantly share code, notes, and snippets.

@karenyyng
Created May 13, 2019 03:55
Show Gist options
  • Save karenyyng/147d49850e81a91c3f26176424ec5279 to your computer and use it in GitHub Desktop.
Save karenyyng/147d49850e81a91c3f26176424ec5279 to your computer and use it in GitHub Desktop.
How to set up and use multiple Github account correctly on the same machine

setting up authentication for each Github account

ref

config file

  • have one entry for each account in the ~/.ssh/config file

For the secondary Github account, choose a different Host value.

Host github.{SECONDARY_KEYWORD}.com
	HostName github.com
	User SECOND_ACCOUNT_USERNAME
	IdentityFile ~/.ssh/SECONDACCOUNT
	PreferredAuthentications publickey
	IdentitiesOnly yes
	ForwardX11Trusted no
	ForwardX11 no

Then when you set up the remote origin URLs for the secondary account should be changed from:

origin  [email protected]:${SECOND_ACCOUNT_USERNAME}/${GIT_REPO_NAME}.git

to

origin  git@github.${SECONDARY_KEYWORD}.com:${SECOND_ACCOUNT_USERNAME}/${GIT_REPO_NAME}.git

by using the command

git remote set-url origin git@github.${SECONDARY_KEYWORD}.com:${SECOND_ACCOUNT_USERNAME}/${GIT_REPO_NAME}.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment