Trying to work on my both my actual \"work\" repos, and my personal repos on git hub, from my computer.
The work account was set up first, and everything works flawl
This answer is for beginners (none-git gurus). I recently had this problem and maybe its just me but most of the answers seemed to require rather advance understanding of git. After reading several stack overflow answers including this thread, here are the steps I needed to take in order to easily switch between GitHub accounts (e.g. assume two GitHub accounts, github.com/personal and gitHub.com/work):
ls -al ~/.ssh
.pub
are your ssh keys so you should have two for the personal
and work
accounts. If there is only one or none, its time to generate other wise skip this.ssh-keygen -t rsa -C "the copied email"
, you'll see:/.../.ssh/id_rsa_work
if generating for work account. provide a password or just enter to ignore and, you'll read something like The key's randomart image is: and the image. done.ls -al ~/.ssh
again.pbcopy < ~/.ssh/id_rsa_work.pub
, replace id_rsa_work.pub
with what you called yours.id_rsa_work
] and navigate toEdit the global git configuration: Last step is to make sure the global configuration file is aware of all github accounts (so to say).
Run git config --global --edit
to edit this global file, if this opens vim and you don't know how to use it, press i
to enter Insert mode, edit the file as below, and press esc followed by :wq
to exit insert mode:
[inside this square brackets give a name to the followed acc.]
name = github_username
email = github_emailaddress
[any other name]
name = github_username
email = github_email
[credential]
helper = osxkeychain
useHttpPath = true
Done!, now when trying to push or pull from a repo, you'll be asked which GitHub account should be linked with this repo and its asked only once, the local configuration will remember this link and not the global configuration so you can work on different repos that are linked with different accounts without having to edit global configuration each time.